[plt-scheme] Multiple values

From: Richard Cleis (rcleis at mac.com)
Date: Tue Feb 21 08:06:12 EST 2006

On Feb 21, 2006, at 2:43 AM, Adam Wick wrote:

> On Feb 21, 2006, at 2:07 AM, Jim Blandy wrote:
>> But in this case, utility and happiness did not bloom magically into
>> existence through the removal of restrictions, as the Scheme mythology
>> requires.  It doesn't seem that people generally find multiple value
>> returns very useful.
>
> Just as a data point, I find multiple value returns very useful, I use 
> them frequently, and they make me very happy.
>
> The example I use most often involves compiler passes. Many times in a 
> compiler pass, for any particularly expression or statement, how you 
> want to recombine the statement after recursing over the sub-parts 
> depends on additional information about those subparts. For example, 
> what variables they reference, the types of the subexpressions, 
> whether or not one of the subexpressions called setjmp() or call/cc, 
> and so on. Multiple value returns offer a very convenient way to pass 
> the information back up the recursion stack without making the 
> routines go exponential.
>
> You can, of course, pass the information back in other ways. Passing 
> tuples back certainly works, but it's a pain; you're constantly 
> allocating the tuple to return, immediately splitting it apart and 
> then let-binding it anyways. It makes more sense to me to just return 
> the values directly, and then let-bind them all at once with 
> let-values. CPS works, and it's what I used before I learned the joys 
> of value/let-values, but CPS does bad things to one's stack trace when 
> trying to hunt down errors. Also, as a minor point, at some point with 
> CPS either you begin to fragment your program past sensibility or your 
> indenting just goes insane.
>
> I'd also like to note that just about every C API I've seen would be 
> vastly improved by multiple value returns. Passing information back 
> through pointer arguments (because you need the return value for a 
> possible error code) is such a deep and true invitation to pain.
>

... which is why I often return structures in C rather than fussing 
with multiple pointers... and structures can also be used in some 
(many?) implementations of Scheme... which is why this thread can go on 
forever because now it can turn into 'multiple values' vs. 
structures... so I am going to work and program with lists only, just 
because programming with blatant limitations is easier to explain (and 
hopefully convert) non-schemers.

rac

>
> -Adam
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.