I understand your point, but if you change the previous code to use fully
qualified syms by changing (p.macros/check-var-at-compile-time *v1*)
to (p.macros/check-var-at-compile-time
p.core/v1)it stills doesn't work. Also doing (ns-resolve 'p.core 'v1)
or (find-var
'p.core/v1) inside the macro gives no result.

So, there is a way in a macro to resolve a sym (maybe fully qualified) to a
compile-time var?


Saludos,
Nahuel Greco.


On Thu, May 29, 2014 at 12:43 PM, Gary Trakhman <[email protected]>
wrote:

> Sorry, did I say Vars? I meant syms.
>
>
> On Thu, May 29, 2014 at 11:41 AM, Gary Trakhman <[email protected]>
> wrote:
>
>> #1, CLJS macros must use fully-qualified vars.  It is possible to resolve
>> using analyzer state, but that requires internal knowledge of the CLJS
>> compiler.
>> #2, it would be going to whatever the binding of *out* is in the current
>> thread, likely it's ending up in the compiled CLJS source code because of
>> how the compiler works :-).
>>
>> There's no difference to the CLJS compiler and emitted code whether that
>> code ends up running in Rhino or a browser.
>>
>>
>> On Thu, May 29, 2014 at 11:02 AM, Nahuel Greco <[email protected]> wrote:
>>
>>> I know ClojureScript doesn't support run-time Vars, but reading the CLJS
>>> code I thought it supported Vars at compile-time, when all is executed
>>> inside the CLJ/JVM runtime. The following code compiles without assert
>>> exceptions for CLJ/JVM but when compiling CLJS the assert in the macro
>>> fails:
>>>
>>> ;;; src/p/macros.clj ;;;
>>> (ns p.macros)
>>>
>>> (defmacro check-var-at-compile-time [v]
>>>     (println "evaluating macro for" v)
>>>     (assert (resolve v) (str "Var " v " not found at ns " *ns*)))
>>>
>>> ;;; src/p/core.clj - compiles ok;;;
>>> (ns p.core [:require p.macros])
>>>
>>> (def v1 3)
>>> (p.macros/check-var-at-compile-time v1)
>>>
>>> (defn foo []
>>>     (def v2 4)
>>>     (p.macros/check-var-at-compile-time v2))
>>>
>>> ;;; src-cljs/p/core.cljs - fails at compilation ;;;
>>> (ns p.core [:require p.macros])
>>>
>>> (def v1 3)
>>> (p.macros/check-var-at-compile-time v1)
>>>
>>> (defn foo []
>>>     (def v2 4)
>>>     (p.macros/check-var-at-compile-time v2))
>>>
>>> In CLJ the vars are found and the println message is printed to the
>>> console when you compile it using lein run or by requiring the ns at
>>> the REPL. In CLJS the assertion fails in compile-time with "Assert
>>> failed: Var v1 not found at ns p.core" and no println message is shown.
>>> So:
>>>
>>> 1- There is a way for macros to access compile-time Vars?
>>> 2- When you compile the CLJS code by using lein cljsbuild once, where
>>> the println output from the macro at compile time is going? (a
>>> minor annoyance)
>>>
>>> Saludos,
>>> Nahuel Greco.
>>>
>>> --
>>> 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 [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at http://groups.google.com/group/clojurescript.
>>>
>>
>>
>  --
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/clojurescript.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to