Your example does work, but it returns the conformed value [a b c] out of 
the macro, which the compiler then tries to evaluate. So the exception is 
coming downstream.

See:

user=> (macroexpand '(test-macro a b c))
[a b c]



On Wednesday, November 22, 2017 at 1:08:22 AM UTC-6, Stanislav Yurin wrote:
>
> Hi,
> Please help me understand following behavior.
> Speccing macro via fdef and calling explain within a macro works, but 
> conform tries to resolve all symbols.
> How to correctly conform macro body from within a macro?
>
> Longer example:
>
> This works:
>
> (spec/def ::test-spec (spec/* any?))
>
> (spec/fdef test-macro
>   :args ::test-spec
>   :ret any?)
>
> (defmacro test-macro [& body]
>   (println body))
>
> (test-macro a b c)
> (a b c)
> => nil
>
>
>
>
> This works:
>
> (defmacro test-macro [& body]
>  (spec/explain ::test-spec body))
>
>
> (test-macro a b c)
> Success!
> => nil
>
>
> This doesn't:
>
>
>
> (defmacro test-macro [& body]
>  (spec/conform ::test-spec body))
>
>
>
> (test-macro a b c)
> CompilerException java.lang.RuntimeException: Unable to resolve symbol: a 
> in this context
>
>
>
>
> Stanislav.
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to