On Mon, 18 Oct 2010 08:58:48 -0400 (EDT) lprefonta...@softaddicts.ca wrote: > Choose functions over macros when you can write an equivalent function.
>From the LISP community, I'd put it slightly stronger: Only use macros when you have to. But you get the same set of reasons (with explanations). > I use macros when: > > a) I have a repetitive pattern in the code that cannot be easily turned > into a function (too much context to pass as args to a function). > You can then hide a binding form in the macro to refer to the context > or directly refer to it (global vars, ...) using form expansion. > You can wrap huge chunks of your code in the macro referring to the context > ( & body) easily. If I understand you correctly, these would be non-hygienic macros. Yeah, those are pretty much "have to". > b) I need to evaluate the args (aka the symbols) to alter the form(s) > generated by the macro and do not want immediate evaluation. And much of the time, this is because you're not sure you want to evaluate the form at all, or may want to evaluate it more than once. Again, a "have to" situation. > c) I need a lighter syntax. You can marshall the symbols themselves as you > wish to refer to other context bindings by sufixing/prefixing the synbol > names. > > I wrote an interactive report utility used by non-lispers and that helped > remove some Clojure syntax requirements that would look obscur > to non-Lispers. The report utility can refer to global bindings while > the user uses nicknames and other syntatic sugars to simplify the calls. > This hides references to the context that would clutter the report code > and make the tool unusable for the average user. In other words, building DSL's. This is a qualified "have to": "have to to meet user requirements." > d) I see some potential in tuning the forms later (maybe to create functions) > but do not want to embark on that journey now. Using macros you can defer > retooling of your code or hide partial retooling until you are ready > to change the top form to its definitive look. General performance reasons? Yeah. In particular, if you can replace run-time decisions with compile time-decisions (loop unrolling, etc.) you can win quite a bit here. Another qualifed "have to": "have to to meet performance requirements". <mike -- Mike Meyer <m...@mired.org> http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. O< ascii ribbon campaign - stop html mail - www.asciiribbon.org -- 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