[racket] Multiple return values

From: Tomasz Rola (rtomek at ceti.pl)
Date: Wed Dec 14 12:20:29 EST 2011

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 ;

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 

This "ignore" is very handy, like below:

[3]> (decode-universal-time (get-universal-time))
43 ;
9 ;
18 ;
14 ;
12 ;
2011 ;
2 ;

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" ;

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.

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             **

Posted on the users mailing list.