On Feb 3, 2009, at 14:01, Mark Volkmann wrote: > Are the following statements true? They aren't discussed at > http://clojure.org/macros, but I think they are true. > > Macros cannot call other macros during their evaluation, but they can > expand to code that calls macros.
Macros can certainly expand to code that uses macros. As for the first part of your statement, it depends on what you mean by "calling" a macro. A macro is just a function marked (with a tag in the metadata) as a macro. More precisely, the var whose value is the macro is tagged as a macro. This tag causes the compiler to call the macro function at compile time, rather than compile a call at runtime. The arguments are therefore unevaluated forms. The definition of a macro is an ordinary function definition, which can use macros just like any other function. These macros will be expanded when the macro is compiled, not when it is executed. If you want it to call another function tagged as a macro, but call it as if it weren't tagged as a macro, you can retrieve its function definition from the var and call it by another name. For example, (def and-fn @(var and)) will assign the function that implements "and" to "and-fn", which is an ordinary function. > Macros cannot use syntactic sugar such as '(items) to create a list > and instead must use non-sugared forms like (list items). The standard quote is not very useful in macro definitions, but syntax-quote (`) is: (defmacro l [x y] `(~x ~y)) (macroexpand-1 '(l 1 2)) --> (1 2) Konrad. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---