HI Christophe,
On May 1, 3:27 am, Christophe Grand <
christo...@cgrand.net> wrote:
> (def check2 describe-checksum) does define a var whose value is the
> macro function itself not the result of evaluating its expansion.
> (def check2 (describe-checksum)) is what you want but then you get
Yes, sorry about the typo.
> clojure.lang.Compiler$CompilerException: NO_SOURCE_FILE:242: Can't use
> qualified name as parameter.
> The cause of this error can be seen with macroexpand-1:> dbtest> (macroexpand-1 '(describe-checksum))
> > (clojure/proxy [java.util.zip.Checksum] [] (clojure/getValue [] 1)
> > (clojure/reset [] nil) (clojure/update ([clojure/b clojure/off clojure/
> > len] nil) ([clojure/b] nil)))
I did notice the clojure/ prefixed to the proxy "method" names, and
was suspicious, but wasn't sure about it.
>
> where you should have got:
>
> dbtest> (macroexpand-1 '(describe-checksum))
> (clojure/proxy [java.util.zip.Checksum] [] (getValue [] 1)
> (reset [] nil) (update ([b off len] nil) ([b] nil)))
>
> only the symbol 'proxy has to be resolved but syntax-quote resolve them all.
Why does this happen? If I have some other constructs in backquote
syntax, e.g. a (let), or a (try), etc. then there's no need to unquote
these symbols, like seen in the snippet below. This feels different to
me than in CL, which isn't necessarily an issue in itself.
user> (defmacro describe-checksum []
`(proxy [java.util.zip.Checksum] []
(~'getValue []
(let [x# 1]
x#))
(reset [] nil)
(update
([b# off# len#] nil)
([b#] nil))))
> You can prevent resolution of a symbol inside a syntax quote by
> prefixing it with ~' but, if the real name of your symbol as no
> importance, better use autogensyms.
>
> (defmacro describe-checksum []
> `(proxy [java.util.zip.Checksum] []
> (~'getValue [] 1)
> (~'reset [] nil)
> (~'update
Yeah, this is where I got caught. In CL, backquote syntax behaves very
nicely in a template-like manner. I do not understand why I need to
unquote the getValue, reset, and update symbols.
Joubert