On Thu, Dec 22, 2011 at 4:54 PM, Peter Danenberg <p...@roxygen.org> wrote:
> Scheme, for instance, obeys the Law of Macro-Parsimony: "don't use
> defmacro," namely, "where defn will suffice;" Clojure, on the other
> hand, is macro-liberal.
>
> In other words, everyone seems to prefer e.g. `(defmacro foo [vars &
> body] `(do ... ~@body))' where `(defn foo [vars thunk] ... (thunk))' would
> suffice; cases in point:
>
>  with-bindings
>  with-bindings*
>  with-in-str
>  with-local-vars
>  with-open
>  with-out-str
>  with-precision
>  with-redefs
>
> Why?

Syntax convenience. Less need for #(...) lambdas cluttering the code.
Particularly helpful when nested, since the #(...) lambda syntax
doesn't nest and you'd start needing (fn [x y] ...)s as well.

Also, if the macro isn't implemented with a thunk passed to a helper
function under the hood, the macro saves a couple of stack frames, and
on the JVM stack can run out relatively easily. With chained lazy
functions (e.g. (map (filter (map (... (partition 3 some-seq)))))) and
recursion this becomes even more significant.

Lastly, in some cases avoiding function calls may save having to box
and unbox primitives, though less so with 1.3 than with previous
versions of Clojure.

-- 
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

Reply via email to