[plt-scheme] Multiple values

From: Gregory Woodhouse (gregory.woodhouse at sbcglobal.net)
Date: Mon Feb 20 21:06:49 EST 2006

On Feb 20, 2006, at 4:01 PM, Bill Wood wrote:

>
> I know I'm coming in *way* late to the discussion (particularly given
> the presence of multiple values in Common Lisp), but while I find some
> elegance in the multiple values mechanism I have to ask, is there a
> killer argument for multiple values over an ordinary function  
> returning
> a (proper or improper) list?

It occurs to me that multiple values provide a syntax that is in some  
way analogous to  patterns in Haskell. For example, I often find  
myself writing code like

(define (something (l)
     (let ((x (car l) (y cadr l))
        ....))

I don't suppose there's any advantage if l is a list of length 2, but  
if it were a stream where you could pick up values from the head in  
this manner, then it might provide some advantage.

BTW, I know I can use improper lists to implement functions taking a  
variable number of arguments (though I seldom, if ever do this), but  
what would I do if I had a function returning some (unknown) number  
of values, but I know I only want to use the first two values (which  
I want to bind to x and y as above)? It would be interesting to have  
something like

(let-values (((x y . z) ... ))

for a situation like this.

===
Gregory Woodhouse
gregory.woodhouse at sbcglobal.net

"You must unlearn what you have learned."
--Yoda





Posted on the users mailing list.