On Thu, Feb 26, 2009 at 9:36 AM, Konrad Hinsen
<konrad.hin...@laposte.net> wrote:
>
> I figured out one way to do it, but it relies on features that are
> perhaps not safe to rely on: I get var first, and then I get the
> var's namespace from its public attribute ns:
>
> (defn qualified-symbol
>   [s]
>   (if-let [var (resolve s)]
>     (symbol (str (.ns var)) (str (.sym var)))
>     s))
>
> This seems to work fine for all cases I can imagine. But I'd love to
> see a cleaner way to do this.

I've got essentially the same thing for use in error-kit:

  (defn- qualify-sym [sym]
    (let [v (resolve sym)]
      (assert v)
      (apply symbol (map #(str (% ^v)) [:ns :name]))))

Of course it depends on the var existing at the time the macro is
expanded, but if that weren't true how could the macro have any idea
what namespace the symbol belonged to?

BTW, I'd recommend avoiding using the name of builtins like 'var' for
your own locals.

--Chouser

--~--~---------~--~----~------------~-------~--~----~
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
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