[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Multiple values and &optional
Just for the record, I had an application today where I really wanted to
write something like
(MULTIPLE-VALUE-BIND (VALUE &OPTIONAL (FOUNDP T))
(FUNCALL (MAGIC-HOOK-FUNCTION THINGY) FUNNY-ARG)
(WHEN FOUNDP
(CACHE-SOME-STUFF THINGY FUNNY-ARG VALUE))
(VALUES VALUE FOUNDP))
The context was that I wanted to have a user hook for a GETHASH-like
protocol, where a second return value indicates whether or not a goodie
was actually found. However, for convenience I wanted to allow the user
hook function to be any function that returns one thing as well, in
which case one assumes that the thing was found. In short, I wanted the
second return value to default to T, not NIL.
I ended up writing this instead:
(LET ((STUFF (MULTIPLE-VALUE-LIST
(FUNCALL (MAGIC-HOOK-FUNCTION THINGY) FUNNY-ARG))))
(WHEN (OR (NULL (CDR STUFF)) (CADR STUFF))
(CACHE-SOME-STUFF THINGY FUNNY-ARG (CAR STUFF)))
(VALUES-LIST STUFF))
--Guy