[plt-scheme] Multiple values

From: Richard Cleis (rcleis at mac.com)
Date: Mon Feb 20 22:22:58 EST 2006

Don't forget about 'apply'; it can be more readable (and writable) than 
call-with-values.

(define (f val-1 val-2 val-3 . the-rest)
   (list val-1 val-2 val-3 the-rest)) ;; a simple program

(define a-list '(call with vals or apply a list ?))

(apply f 'call 'with a-list)

rac


On Feb 20, 2006, at 7:06 PM, Gregory Woodhouse wrote:

>
> 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
>
>
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.