Ray Dillinger scripsit:

> It would be a better expression than we have now, but it would still 
> inject bindings for return values a and b into the calling 
> environment, breaking lexical scope.  

No, you've misunderstood me.  The sole purpose of the 2 is to inform the
compiler that the continuation should expect two arguments.  There is no
injection into the caller's scope at all; the names a and b remain purely
local.  Perhaps less bare-bones examples would be useful:

(define sin+cos (lambda 2 (x) (values (sin x) (cos x)))

(define set-them-up (lambda 0 () (set! this 'that) (set! that 'this)))

which definitively returns 0 values, and thus cannot be used in ordinary
expression positions independent of what set! may return.

In the first case, even a fairly feeble compiler can do the work
itself, and in the second case, appending (values) to the lambda body
does the same work.  But there are more complex cases where the
compiler can't determine the number of values returned, as where
VALUES is applied to a list whose length the programmer knows but the
compiler doesn't.

> If lexical scope is to be preserved, then the call site rather than
> the function has to bind the values to be recieved from the function 
> (as in the receive form).  But if first-class functions are to be
> preserved, then the number of returns is a property of the function 
> and not a property of the call site.  

Absolutely.

> It's probably not a coincidence that 'parameters' and other forms 
> that break lexical scope come under consideration at roughly the 
> same moment in history as multiple returns. 

Parameters are a clean form of dynamic scope using mutable values instead
of variables, and dynamic scope has been around since the dawn of time.
How they are to be implemented, with shallow binding or deep binding or
what, is a matter for the local implementation.

-- 
John Cowan   [email protected]  http://www.ccil.org/~cowan
Most languages are dramatically underdescribed, and at least one is
dramatically overdescribed.  Still other languages are simultaneously
overdescribed and underdescribed.  Welsh pertains to the third category.
        --Alan King

_______________________________________________
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss

Reply via email to