[r6rs-discuss] Thing1: Dealing with VALUES
John Cowan
cowan at ccil.org
Wed Dec 2 18:50:55 EST 2009
David Rush scripsit:
> The full article including references with source code links is at
> <http://scheme-punks.org/wiki/index.php?title=Auric>. This is really
> just an abstract.
>
> Cheney Meets a Chicken
> or
> Henry Baker Redux: CONS Should STILL Not CONS Its Arguments
> or
> Lambda the Ultimate Algebraic Constructor
I have read your whole paper, and I don't have time/energy/health level
enough to give it a full response right now, so here are some scattered
thoughts instead.
1) (lambda foo . body) isn't quite what you say, because foo is
a first-class list, not an opaque cookie that only a destructuring
operation can access. This is one the one place where Scheme control
meets Scheme data: a Schemoid language that didn't have lists as a data
structure would need a different mechanism for writing variadic functions.
2) Under CPS, multiple returns are just multiple arguments passed to
the continuation, but while there is syntactic sugar for specifying a
fixed number, or minimum number, of arguments, there is no such sugar for
specifying a fixed number of results. This matters because if something
is sugared the compiler can optimize it freely. Typically LET-VALUES is
implemented on top of CALL-WITH-VALUES, but because the consumer is not a
first-class procedure, it can't escape and the compiler can in principle
implement LET-VALUES more efficiently. Likewise for SET! vs. boxes, or
R[01]RS CATCH vs. R[2-]RS CALL/CC. Often, of course, this opportunity
to optimize is not worth having: many Scheme compilers do in fact compile
SET! using boxes.
3) There are a couple of possibilities for adding such syntactic sugar:
I suggested (LAMBDA n (arg ...) . body), where n is a compile-time integer
constant, as a declaration that this procedure returns exactly n values.
One could also support (>= n) instead of n, to indicate returning at
least n values.
4) Many languages go with "out parameters", something like (LAMBDA (x y
(a :out) (b :out) . body). Here a and b are bound but undefined, and you
define them with SET! or a specialization thereof. Exiting the procedure
is equivalent to returning (values a b). This idea has been around since
the beginning of HLLs: Fortran used call by reference to the right effect,
and Algol 60 had the more general call by name. Ada is I think the most
recent language to have in, out, and "in out" (call by value and return)
arguments; they are allowed only in subroutines, not in functions.
--
John Cowan cowan at ccil.org
"You need a change: try Canada" "You need a change: try China"
--fortune cookies opened by a couple that I know
More information about the r6rs-discuss
mailing list