4 ms·
You could save a little work by noting that when is a special case of if and then writing when-let as a special case of if-let. Something like: (defmacro whe
by nickdrozd 8y ago
You could save a little work by noting that when is a special case of if and then writing when-let as a special case of if-let. Something like:
(defmacro when-let (bindings &rest body)
`(if-let ,bindings
(progn ,body)))
That's how it's implemented in Emacs at least. Maybe there are some edge cases involving declarations or whatever where this wouldn't work.
- stevelosh 8y agoYou'd need to parse out the declarations, yeah. Otherwise they'd get shoved inside the progn which wouldn't work.
- junke 8y agoYou could also introduce a "locally" form (for those wondering: http://www.lispworks.com/documentation/lw61/CLHS/Body/s_locall.htm http://www.lispworks.com/documentation/lw61/CLHS/Body/s_loca...)