2009/4/21 Mark Volkmann <r.mark.volkm...@gmail.com>: > > I didn't explain my question well enough. Suppose I define a macro > with defmacro and have several calls to it in my code. When are those > calls expanded to the code inside the macro? Is that at read-time?
Maybe the example I gave (by using the macro 'defn) was not as clear as I intended. But really, defn is a regular macro created via defmacro, so the point is proven here as with any user defined macro. HTH, -- Laurent > > On Mon, Apr 20, 2009 at 5:34 PM, Laurent PETIT <laurent.pe...@gmail.com> > wrote: >> >> Hello, >> >> Apparently, no: >> >> 1:85 user=> (macroexpand-1 '(defn hello [] "world")) >> (def hello (clojure.core/fn ([] "world"))) >> 1:86 user=> (read-string "(defn hello [] \"world\")") >> (defn hello [] "world") >> 1:87 user=> >> >> read-string did not expand defn. >> >> I think it's 'eval that expands macros and compiles forms. >> >> Regards, >> >> -- >> Laurent >> >> 2009/4/21 Mark Volkmann <r.mark.volkm...@gmail.com>: >>> >>> In my Clojure article at http://ociweb.com/mark/clojure/article.html I say: >>> >>> "Clojure code is processed in three phases: read-time, compile-time >>> and run-time. At read-time the Reader reads source code and converts >>> it to a data structure, mostly a list of lists of lists .... At >>> compile-time this data structure is converted to Java bytecode. At >>> run-time the bytecode is executed. Functions are only invoked at >>> run-time. Macros are special constructs that look similar to >>> functions, but are expanded into new Clojure code at read-time." >>> >>> Is it correct to say that macros are expanded at read-time? > > -- > R. Mark Volkmann > Object Computing, Inc. > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---