The
Test if a function has returned multiple values:
(setf cl:*multiple-values* nil)
(let ((result (function ...)))
(if cl:*multiple-values*
(do-something-with *rslt* ...)
(do-something-with result ...))
... )
Do not use
(let ((cl:*multiple-values* nil)
(result (function ...)))
(if cl:*multiple-values*
(do-something-with *rslt* ...)
(do-something-with result ...))
... )
This doesn't work because 'function' is evaluated in the global XLISP
environment, where the lexical let
binding of the
The XLISP progv special form can be used to encapsulate a multiple value call while automatically restoring the old values at the end like this:
(values 1 2 3) => 1
cl:*multiple-values* => T
*rslt* => (1 2 3)
(progv '(cl:*multiple-values* *rslt*) '(nil nil)
(let ((result (function ...)))
(if cl:*multiple-values*
(do-something-with *rslt* ...)
(do-something-with result ...))))
cl:*multiple-values* => T
*rslt* => (1 2 3)
Note: All functions returning multiple values set