Gentlemen---
Thanks for fixing my newbish error and showing me a better way to
do it!
Nick.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to
Hi,
as David has said, your macro works only for literal
values, which doesn't make much sense.. I would
implement i-let as follows:
(defmacro let-default
[bindings body]
`(let ~(vec (mapcat (fn [[sym value default]]
`(value# ~value
~sym
On Mon, Jul 27, 2009 at 8:33 PM, nchubrich nicholas.chubr...@gmail.comwrote:
Anyway I'd appreciate any critiques of the implementation; whether
it's a useful thing or not; if there are more idiomatic ways of doing
the same thing; and, if yes-no to the aforetwo, where's the best place
to add
Unless you want the default value for a non initialized boolean value to be
true ...
(let [x (or false true)] = whooops
In defense: ad hoc solutions don't need 100% coverage,
mea culpa: I shouldn't have switched to it in discussing the macro.
mea maxima culpa: I hesitated mentioning it at
I've been learning Clojure. I just wrote a macro to be used like so:
(i-let [x nil 4
y 2 6
z nil 10]
(+ x y z))
= 16
I.E. if the first value in the triple is nil, bind it to the second
value in the triple. This is useful when you want to let something
that might be nil and
(let [ x (or nil 4)
y (or 2 6)
z (or nil 10)]
(+ x y z))
= 16
This use of 'or' is fairly idiomatic, and not just in Lispish. Less
typing than 'if'. And you can use it or not, unlike i-let, which
forces you to put in a default for all bindings.
Regarding the implementation of
2009/7/28 David Miller dmiller2...@gmail.com
(let [ x (or nil 4)
y (or 2 6)
z (or nil 10)]
(+ x y z))
= 16
This use of 'or' is fairly idiomatic, and not just in Lispish. Less
typing than 'if'. And you can use it or not, unlike i-let, which
forces you to put in a