Qualifying Symbols in Clojurescript macro

106 views
Skip to first unread message

Kaylen Wheeler

unread,
Apr 13, 2016, 3:24:39 AM4/13/16
to ClojureScript
I have the following function that I am using to fully qualify symbols in a macro:

(defn qualify
"Convert a symbol to a qualified symbol. If the
symbol does not already refer to an existing var,
default to the current namespace."
[sym]
(let [res (resolve sym)
ns (or (and res (-> res (meta) (:ns) (.name) (name)))
(-> *ns* (.name) (name)))

nme (name sym)]
(symbol ns nme)))


I would like to know how to convert this so that it can be called from within a clojurescript macro. I know that all cljs macros must actually be written in clj. How do I access this kind of information when compiling cljs?

Message has been deleted

Kaylen Wheeler

unread,
Apr 14, 2016, 6:19:17 PM4/14/16
to ClojureScript
Solved. I seem to have gotten my wires crossed a little.

As long as I restrict this defn to clj only, it will work in a clojurescript macro.

Yuri Govorushchenko

unread,
Apr 14, 2016, 8:57:50 PM4/14/16
to ClojureScript
Hello Kaylen,

instead of Clojure's resolve you'd probably need to use cljs.analyzer/resolve-var.

Also you may find useful this article about writing macros in ClojureScript, it has some nice little code examples:
http://blog.fikesfarm.com/posts/2015-12-18-clojurescript-macro-tower-and-loop.html
Reply all
Reply to author
Forward
0 new messages