On Sat, 05 Sep 2009 23:18:25 -0400, Ray Dillinger <[email protected]> wrote:
> In a pure mathematical sense, a function takes one argument and returns
> one value. What we think of as functions taking multiple arguments are
> functions taking a tuple (or an environment) as an argument, and what
> we think of as functions returning multiple values are functions
> returning a tuple (or an environment) as a result.
> So far so good. It's a symmetry, as you point out. But there's an
> asymmetry in our mapping of this mathematical reality into our
> language syntax, where one maps naturally onto a list form and one
> doesn't.
> The semantics of multiple returns as opposed to returning a list and
> multiple arguments as opposed to passing a list bear some deep thought.
> What we wind up doing is modeling the passing of environments, and
> while lambda is good for the one direction, our return mechanisms so
> far aren't sufficiently expressive to do it.
Multiple return values do map fairly easily into list form.
(call-with-values (lambda () (values 1 2 3)) (lambda f f))
The big contribution, I see of multiple return values is allowing us to
describe the binding and return of multiple values at a syntactic level
instead of forcing it to be encoded into an unnecessary intermediate
structure that shouldn't be explicitly visible. Just as we don't always
use (lambda args ...), and instead use the syntactic means of binding them
without exposing the intermediate list structure, multiple return values
allow us to hide the unnecessary information. Once this information is
hidden, either in multiple return values or in function arguments, this
makes the code clearer and also enables optimizations that can't be done
otherwise.
I'd call that symmetry enough for me. The optimization is nice, but it's
the clarity that's really important.
Aaron W. Hsu
--
Of all tyrannies, a tyranny sincerely exercised for the good of its
victims may be the most oppressive. -- C. S. Lewis
_______________________________________________
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss