On Tue, Mar 15, 2011 at 11:17 AM, Armando Blancas <armando_blan...@yahoo.com> wrote: >> If so, it's only the subforms not in operator position that get >> macroexpanded first. Otherwise >> >> user=> (defmacro qqq [] 'if) >> #'user/qqq >> user=> ((qqq) (even? 42) "boo!") >> #<CompilerException java.lang.Exception: Unable to resolve symbol: if >> in this context (NO_SOURCE_FILE:607)> >> >> would instead produce "boo!", as (qqq) would be expanded to if and >> then (if (even? 42) "boo!") would be parsed and discovered to be an if >> special form. > > I think your macro (qqq) is being expanded to if: it's right there in > the error message. The parsing of (if (even? 42) "boo!" as a special > form cannot occur because the processing is past the opening paren; > macroexpanding the first element won't produce the re-evaluation of > the form as a whole, which is the only case where the 'if' is > recognized as the start of a special form. I find it easier to think > of special forms and not special symbols.
Yes, I know. It disproved the suggestion that it was expanding macros there *before* checking for special symbols. That was precisely my point with that demonstration. >> On the other hand, >> >> user=> (quote (qqq)) >> (qqq) >> >> seems to indicate that nothing is macroexpanded before special form >> parsing occurs, or it would have output if instead of (qqq), unless >> quote it another special case. > > Well, quote is a special form, of course. I'd think that special forms > can happen after macroexpansion, as is the case when a macro produces > a conditional. When the macro expands into a special form, or a form involving a special subform, this seems to be true. On the other hand it cannot convert an s-expression *into* a special form unless s-expression was the macro invocation itself. (qqq something) can expand to (if something), but ((qqq) something) cannot expand to (if something) and have this still be treated as the if special form, for the reasons already noted. -- 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 Note that posts from new members are moderated - please be patient with your first post. 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