4 ms·
Maybe I'm missing the point of the exercise, but since the author is already using Alexandria in these examples, and Alexandria provides when-let and if-let mac
by TeMPOraL 8y ago
Maybe I'm missing the point of the exercise, but since the author is already using Alexandria in these examples, and Alexandria provides when-let and if-let macros as well, then... why not just explain - or at least compare with and discuss - the implementation in Alexandria?
Skipping docstrings, those are exactly:
(defmacro if-let (bindings &body (then-form &optional else-form))
(let* ((binding-list (if (and (consp bindings) (symbolp (car bindings)))
(list bindings)
bindings))
(variables (mapcar #'car binding-list)))
`(let ,binding-list
(if (and ,@variables)
,then-form
,else-form))))
(defmacro when-let (bindings &body forms)
(let* ((binding-list (if (and (consp bindings) (symbolp (car bindings)))
(list bindings)
bindings))
(variables (mapcar #'car binding-list)))
`(let ,binding-list
(when (and ,@variables)
,@forms))))
- zshrdlu 8y agoWould you rob the author the fun of reinvention and rediscovery?
- stevelosh 8y agoAlexandria's versions are basically the same as the "multiple bindings" versions, about halfway through the post[1]. So they are explained/compared/discussed... I just didn't mention that those versions happen to be in Alexandria. I suppose I could add a note, though calling out a particular library for having a less than ideal implementation seems a little rude. [1]: They do allow a single binding as a special case, true.
- TeMPOraL 8y ago> calling out a particular library for having a less than ideal implementation seems a little rude Why? As long as you call it "less than ideal", and not say "it sucks" :). Maybe in the end a patch will find its way upstream; I hear that someone is contributing to this library, sometimes.