On Feb 26, 2009, at 13:04, Konrad Hinsen wrote:
> Of course that should better be
...
>
> so that it doesn't mess up already qualified symbols.
And even that is not good enough: it won't handle symbols/vars from
other namespaces that are referred to. And that's where I am lost. I
can't find any way to obtain the qualified symbol that an unqualified
one would resolve to. There are a couple of ways to get the var it
refers to (for example ns-resolve), but I don't want the var, I want
the symbol, for use in a macro.
I checked the compiler source code and found
clojure.lang.Compiler.resolveSymbol, which does exactly what I need,
but it's not public.
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.
Konrad.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---