guns writes: > On Tue 21 Jan 2014 at 07:33:43PM -0800, Alejandro Ciniglio wrote: > >> I was wondering if people had advice on when to write these sorts of >> macros vs. when to just use the trivial expansion in the code? (Or >> alternatively, what am I missing in this macro definition?) >> >> (defmacro go-loop >> "Like (go (loop ...))" >> [bindings & body] >> `(go (loop ~bindings ~@body))) > > go-loop needs to be a macro to capture the unevaluated let bindings: > > (go-loop [i 0] …) > > If go-loop were a function, this code would throw an error because i is > undefined. > > guns
That's not the question - it was about: (go (loop [...] ...)) vs. (go-loop [...] ...) To answer it: (go (loop ...)) is a frequently used idiom, so someone decided that it's worth adding a trivial macro to make it look a bit cleaner. It's more or less the same for `with-open'.: You could just write the (let [...] (try ... (finally ...))) yourself, but it's much easier to understand the purpose when you read `with-open'. -- Moritz Ulrich
pgpZyu7NHe8M4.pgp
Description: PGP signature