This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Multiple value return propogation

3 posts · 2758 views

:arrow: :arrow: :idea: :arrow:
I want to do something like this.
(defun func ()
(multiple-value-bind (arg ...an unknown amount of returns) (func2)
(if (...a test using arg value...) (progn ;;do something) (values arg ..somehow return all values returns by func2))))
In other words i want to 'propogate the multiple return value returned by func2. Is there any way to do this?
Thx :mrgreen:

Re: Multiple value return propogation

Short answer: Yes, look at MULTIPLE-VALUE-LIST.

I assume that you already know that a function like,
(defun my-floor (x y)
   (floor x y) )
will propagate the multiple values from FLOOR. Not the most flexible method, since it won't work if you want to store the return from FLOOR first. The general way is to use MULTIPLE-VALUE-LIST like so,
(defun func ()
  (let ((vals (multiple-value-list (func2))))
    (cond ((test (car vals))
           ...do something... )
          (t (values-list vals)) )))
All sorts of things you can do along these lines. Check out MULTIPLE-VALUE-COMPOSE in the Alexandria utility library for some real world working of this.

Best,
Zach S

Re: Multiple value return propogation

That['s exactly what i wanted to do. Thx, especially for that reference to multiple-value-compose :D :D