Hi,

I needed (and created) a macro to generate keywords from symbols. I
couldn't find anything ready, and I am still not completely
comfortable with the solution I came up with. Any suggestions for
improvement?

Here is what it should do:
=> (def name1 "A")
=> (to-keyword name1)
:user/name1
=> (ns namespace2)
=> (def name2 "b")
=> (ns user)
=> (use namespace2)
=> (to-keyword name2)
:namespace2/name2

And the code:

(defmacro to-keyword
  [sym]
  `(keyword (second (re-find #"#'(.*?)/" (str (resolve '~sym)))) (name
'~sym)))

I feel that the least that could be done is that the regex could be
improved (I don't know regexes almost at all)...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to