Macros and, more specifically, syntax-quotes are not conceptually
hard. Nested syntax-quotes though are certainly more complicated to
follow, but not any harder from a conceptual point of view. I've
written about what the expansion algorithm does in the wiki. You can
find some info here:

http://en.wikibooks.org/wiki/Learning_Clojure#Reader_Macros

Just follow the rules and you'll figure out what's going on behind the
curtains.

As for expansion per se, I use a simple trick. Just "quote" it and
you'll see the result. For instance:

Want to see what happens to ``(~a) then just
'``(~a)

If you want to break that down, keep in mind that the expansion starts
from the innermost syntax-quote. Like the wiki says:

If the syntax-quote syntax is nested, the innermost syntax-quoted form
is expanded first. This means that if several ~ occur in a row, the
leftmost one belongs to the innermost syntax-quote.

So in the previous example do this:
'`(~a)

then apply another '` to whatever you get as the result. This way you
can break it down to successive steps.

Hope that helps.

Rock

P.S. I've just realized that I'm going to have to update the syntax-
quote expansion algorithm in the wiki because with the changes
concerning lazy sequences it seems things have changed slightly, but
the essence of what I have told you is the same.

Perhaps Rich can write it out for us explicitly right away. It would
be greatly appreciated.

On May 28, 9:10 pm, CuppoJava <patrickli_2...@hotmail.com> wrote:
> Thank you Meikel for going to the trouble of writing out the full
> macro. It's going to take me a while to decipher it, and hopefully
> grasp some understanding at the end of it.
>
> I find defblockfn very useful for functions that take a single
> function as one of the parameters.
>
> Macros are much harder and more error-prone to write than functions,
> so almost all of my macros do nothing but wrap a body in a function.
>
> "One technique, which was
> helpful was to just call the defblockfn macro and then
> expand the call to freshly defined macro.
>
> (defblockfn foo [a b c] ...)
> (macroexpand-1 '(foo :a :b :c)) "
>
> Could you explain a bit more what you mean by that? I don't quite
> understand what you're saying, but it sounds potentially very useful.
>
> Thanks again
>   -Patrick

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to