Page 1 of 1

Multiple value return propogation

Posted: Sat Sep 06, 2008 9:19 pm
by Harnon
: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

Posted: Sat Sep 06, 2008 10:44 pm
by smithzv
Short answer: Yes, look at MULTIPLE-VALUE-LIST.

I assume that you already know that a function like,

Code: Select all

(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,

Code: Select all

(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

Posted: Sun Sep 07, 2008 11:51 am
by Harnon
That['s exactly what i wanted to do. Thx, especially for that reference to multiple-value-compose :D :D