4 ms·
They are basically the same macros, but without the use of bindings (more brevity). So if-let and when-let are not really anaphoric. In Common Lisp, I use b-w
by felideon 16y ago
They are basically the same macros, but without the use of bindings (more brevity).
So if-let and when-let are not really anaphoric.
In Common Lisp, I use b-when and b-if that Kenny Tilton wrote:
(defmacro b-when (bindvar boundform &body body)
`(let ((,bindvar ,boundform))
(when ,bindvar
,@body)))
(defmacro b-if (bindvar boundform yup &optional nope)
`(let ((,bindvar ,boundform))
(if ,bindvar
,yup
,nope)))
Usage:
(b-when foo (plusp 1)
(frob foo))
- Hexstream 16y agoI find your lack of parentheses disturbing. I'd personally prefer: (b-when foo (plusp 1) (frob foo)) These implementations also don't handle declarations correctly ;P A surprisingly tricky topic.
- felideon 16y agoHmm, did you mean... (bwhen (foo (plusp 1)) (frob foo)) bwhen is actually the first version of the macro, heh. It does seem a bit more idiomatic with parens, but I've gotten used to the other.