[racket] Multiple return values

From: Markku Rontu (markku.rontu at iki.fi)
Date: Thu Dec 15 07:03:45 EST 2011

Named return values, ah the dream of symmetry.

-Markku

----- Reply message -----
From: "Zayr Okale" <zayr.okale at gmail.com>
To: "Tomasz Rola" <rtomek at ceti.pl>
Cc: <users at racket-lang.org>
Subject: [racket] Multiple return values
Date: Thu, Dec 15, 2011 13:39


On 14/12/2011 21:20, Tomasz Rola wrote:
> On Wed, 14 Dec 2011, Zayr Okale wrote:
>
>> Hello, everyone.
>>
>> Can someone please explain to me multiple return values? Not what it does,
>> I understand that much, but what is this feature for? In what situations is
>> it useful?
> I am not sure how much usable values/call-with-values are in Scheme. In
> Common Lisp, some functions return multiple values, for example floor:
>
> [1]>  (floor 13 4)
> 3 ;
> 1
>
> In this case, one computation is performed to have two values, and user is
> free to use only one of them or both. She can also signal her intentions
> about ignoring some of the returned values with (declare (ignore ...)),
> which, I guess, should be used by compiler/interpreter to optimize things
> better.
>
> This "ignore" is very handy, like below:
>
> [3]>  (decode-universal-time (get-universal-time))
> 43 ;
> 9 ;
> 18 ;
> 14 ;
> 12 ;
> 2011 ;
> 2 ;
> NIL ;
> -1
>
> Also, comparing to C, this would be done by passing pointer to C struct to
> the function, which would then fill it with days and month etc. So, I
> think multiple values could be used instead of passing/returning
> structures. From optimization point, it would be tricky to declare things
> like "I pass this structure here to you, but I only need a month number".
> And it would be tricky (and trashy) to have multitude of smaller
> functions, each for computing year, month, hour from number of seconds.
>
> Last but not least, this may serve as a way to help using information in
> place where it is needed:
>
> [4]>  (read-line )
> aa aa
> "aa aa" ;
> NIL
>
> Here, read-line returns bot a line of text and a value signaling if there
> was EOF condition. Again, one can ignore EOF-value if this is what one
> really wants.
>
> Regards,
> Tomasz Rola
>
> --
> ** A C programmer asked whether computer had Buddha's nature.      **
> ** As the answer, master did "rm -rif" on the programmer's home    **
> ** directory. And then the C programmer became enlightened...      **
> **                                                                 **
> ** Tomasz Rola          mailto:tomasz_rola at bigfoot.com             **

I even do understand what multiple return values are useful for in CL: 
"okay, the function calculates other potentially useful values anyway, 
so no reason not to make them available".

Unfortunately, this scenario doesn't apply to Racket. And this is 
exactly what prompted my question. Since one of the reasons behind 
multiple return values is, as David Van Horn pointed out, symmetry with 
multiple input values (function arguments), then why optional input 
values are allowed, but optional output values aren't?

The situation when all the return values are of equal importance, yet 
returning a struct or a list is not convenient is, IMHO, quite rare.
_________________________________________________
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20111215/4a90a0f6/attachment.html>

Posted on the users mailing list.