Hey Andy! On Mon, Jan 20, 2014 at 12:38:23PM -0800, Andy Smith wrote: > So if we can always reformulate in this was, why cant let be implemented as > a macro rather than a special form?
It can. Quite easily, in fact: (defmacro my-let [bindings & body] (if (empty? bindings) `(do ~@body) (let [var (first bindings) val (second bindings) others (nnext bindings)] `((fn [~var] (my-let ~others ~@body)) ~val)))) This is going to be a fair bit less efficient than the existing 'let' implementation, though. The special form is, as far as I understand it, an optimisation so that we're not constantly creating and destroying function objects for the sake of local bindings (which are much simpler than closures, which is what functions require here). If there's another reason then I'm hoping someone will correct me, but I can't think of any other reasons at the moment. Carlo
signature.asc
Description: Digital signature