Hi there,
I just stumbled over the lack of a multiple-value-or in CL, so here's a patch hat implement it in alexandria (with the first value specifying which value's non-NIL-ness to consider):
It may look horrifying, but it allows pleasant things like:
(multiple-value-or 1 (gethash key table) (gethash key alternative- table))
and other niceties.
Hope you like it,
On Dec 3, 2007, at 16:51, Andreas Fuchs wrote:
<multiple-value-or.patch>
Eek, fe[nl]ix told me about a brain fart in that patch: I am using apply #'values instead of values-list. Here's an updated patch:
Cheers,
On Dec 3, 2007 4:19 PM, Andreas Fuchs asf@boinkor.net wrote:
On Dec 3, 2007, at 16:51, Andreas Fuchs wrote:
<multiple-value-or.patch>
Eek, fe[nl]ix told me about a brain fart in that patch: I am using apply #'values instead of values-list. Here's an updated patch:
Thank you! Merged, but as NTH-VALUE-OR instead, as it seems to represent the intention better. In my mind MULTIPLE-VALUE-OR would be something like
(values-list (or (every #'identity (multiple-value-list form1)) ...)
or maybe
(values-list (or (let ((values (multiple-value-list form1))) (and (car values) values)) ...))
Also: perhaps we should return only N first values from all but the last form? That would allow implementation without consing up a values list for each form.
Are there cases where one wants N+M values, but tests only the Nth one?
Cheers,
-- Nikodemus
alexandria-devel@common-lisp.net