And the problem with the plain (keyword x) approach is how the
namespace resolving works in that case. I can see that some things
have been improved in Clojure 1.1 compared to 1.0, but there is still
one thing:

In 1.1. if I call (keyword 'foo/bar) i'll get :foo/bar. OK, because
the namespace is explicitly mentioned in the call.
But, if I want to create keyword from any var imported from another
namespace, using a macro to create a symbol:
(defmacro [sym] `(keyword '~sym))
(ns foo)
(def bar "A")
(ns user)
(use foo)
(to-keyword bar) ;; note that bar is actually the foo/bar
:bar ;;it should be :foo/bar!

On Aug 25, 12:47 pm, Dragan Djuric <draga...@gmail.com> wrote:
> I needed a macro if I wanted to avoid ' in calls. It may seem as
> nitpicking but (to-keyword name) is more readable and less error prone
> than (to-keyword 'name) if I need to  use it in lots of places.
>
> On Aug 24, 8:38 pm, Achim Passen <achim.pas...@gmail.com> wrote:
>
> > Hi!
>
> > Am 24.08.2009 um 18:31 schrieb Dragan Djuric:
>
> > > 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?
>
> > If I understand you correctly, you'd like to convert symbols which  
> > name vars to keywords qualified with the namespace which contains the  
> > var's definition. You don't really need a macro for that, a regular  
> > function will do. Here's a version using var metadata:
>
> >         (defn resolve-to-kw [sym]
> >           (let [md (meta (resolve sym))]
> >             (keyword (-> md :ns ns-name name) (-> md :name name))))
>
> > Hope this helps.
>
> > Kind Regards,
> > Achim
--~--~---------~--~----~------------~-------~--~----~
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