Multiple value return propogation

Discussion of Common Lisp

Multiple value return propogation

Postby Harnon » Sat Sep 06, 2008 9:19 pm

: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:
Harnon
 
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am

Re: Multiple value return propogation

Postby smithzv » Sat Sep 06, 2008 10:44 pm

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
smithzv
 
Posts: 94
Joined: Wed Jul 23, 2008 11:36 am

Re: Multiple value return propogation

Postby Harnon » Sun Sep 07, 2008 11:51 am

That['s exactly what i wanted to do. Thx, especially for that reference to multiple-value-compose :D :D
Harnon
 
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 5 guests

cron