accessing cljs code from inside a macro

125 views
Skip to first unread message

Yehonathan Sharvit

unread,
Aug 25, 2014, 4:15:51 PM8/25/14
to clojur...@googlegroups.com
I would like to write a macro that calls a cljs function.
The problem is that the macro is defined inside a clj file and when I require the namespace that contains the cljs code I receive the following compilation error:


Caused by: java.io.FileNotFoundException: Could not locate user__init.class or user.clj on classpath:


This is my code snippet:


(ns cljs_explore.macros
(:require [user :as user]))


Gary Trakhman

unread,
Aug 25, 2014, 4:23:47 PM8/25/14
to clojur...@googlegroups.com
You can't load CLJS namespaces from clojure, you'll have to fully-qualify CLJS symbols inside the emitted macro code, eg https://github.com/clojure/core.async/blob/master/src/main/clojure/cljs/core/async/macros.clj?MobileOptOut=1#L16




--
Note that posts from new members are moderated - please be patient with your first post.
---
You received this message because you are subscribed to the Google Groups "ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojurescrip...@googlegroups.com.
To post to this group, send email to clojur...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.

Yehonathan Sharvit

unread,
Aug 25, 2014, 4:45:07 PM8/25/14
to clojur...@googlegroups.com
Thanks Gary!


You received this message because you are subscribed to a topic in the Google Groups "ClojureScript" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojurescript/pgqaI90dkiM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojurescrip...@googlegroups.com.

Joel Holdbrooks

unread,
Aug 30, 2014, 1:33:50 PM8/30/14
to clojur...@googlegroups.com

Can you be a little more clear as to what you are doing? If you are literally trying to call a ClojureScript function from Clojure, it will not work. However, it is possible to resolve ClojureScript symbols from Clojure for the purposes of macro code generation but you'll need to use the ClojureScript analyzer to do this.

Yehonathan Sharvit

unread,
Aug 31, 2014, 10:47:29 AM8/31/14
to clojur...@googlegroups.com

I am trying to write a macro that calls cljs code.
How can I use the ClojureScript analyzer to resolve ClojureScript symbols from Clojure?


For example I have:


a cljs namespace

(ns user.my-cljs)


(defn foo [] 4)

a clj namespace

(ns my-macros)

(defmacro my-macro [] my-cljs/foo)

What is the best way to access my-cljs/foo from inside the macro?

Joel Holdbrooks

unread,
Sep 5, 2014, 2:06:37 PM9/5/14
to clojur...@googlegroups.com

What do you mean by "access"? Do you mean the actual source code for the symbol?

Reply all
Reply to author
Forward
0 new messages