> > Macroexpansion is part of the expression evaluation mechanism. In your > example > > > (defn foo > ([bar] (foo bar :default)) > (special-fn-spec)) > > the whole defn-form is macroexpanded first, yielding something like > > (def foo (fn ([bar] (foo bar :default)) (special-fn-spec)) > > Then the fn form is evaluated, yielding a compiled function. At that point, > the compiler checks its syntax, and finds two bodies, one well-formed (arg > list followed by expression) and a second ill-formed one (just an > expression). The function bodies are *not* macroexpanded because they are > not evaluated either. The only other subform of your example that is ever > macroexpanded is (foo bar :default). > > There are a couple of ways to generate function bodies programmatically, > but it is difficult to give useful advice without knowing what you need this > for. > > Konrad.
Thanks Konrad, that makes sense. I suppose I was a bit confused about when macroexpansion occurs. My real use-case involves wrapping a Java object, which has a number of methods with varying numbers of optionally nullable parameters. E.g. DatabaseMetaData#getExportedKeys(String, String, String) In this method, the first two parameters may be null. So, my fn looks like this: (defn exported-keys ([table] (exported-keys nil table)) ([schema table] (exported-keys nil schema table)) ([catalog schema table] (fetch-metadata-rs .getExportedKeys catalog schema table))) I was trying to automatically generate the final function body since it duplicates the parameter list, and I expect to have a lot of these kinds of methods. Although, it's not too bad as it is (I've already pulled some common bits into fetch-metadata-rs). Not sure if that makes sense or not... ? Cheers, Stuart -- 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