On May 22, 2011, at 7:12 AM, Claus Reinke wrote:
>
> For instance, block_lambdas seem to include a form of generalized jump, a
> callable thing that does not return to the caller (Tennent mentioned such
> things as 'sequels',
> so they were probably known in Algol times, but I have
> not seen them implemented, short of (delimited) continuations).
Yes, Pascal had them and so presumably did Algol 60. It was simply a goto
statement whose target label was outside of the current procedure in an
enclosing scope. The Pascal compiler writers I ran with called these "bad
goto's" (bad in the sense that it took extra mechanism to make them work). I
learned the term from people who had been involved in the compilers for the
Burroughs 5500 Algol machines so I presume they were present there and in Algol
in general. Too lazy right now to dig out the Algol 60 Report to check.
In Smalltalk, this is the semantics for a ^ in a block, eg [^nil] which
returns from the enclosing method invocation unlike [nil] which returns from
the block invocation. Ruby generalized it to deal with explicit control
statements and break/continue style escapes.
> We just need to ensure that the callable's definition context is still active:
Yes, for example the design sketch at the very end of
http://lists.squeakfoundation.org/pipermail/squeak-dev/2001-April/008237.html
describes an efficient way to implement this for Smalltalk blocks.
>
> function A() {
> let ret = {|x| return x; }; // sequel
> let inc = {|x| x+1 }; // function
> let j = 0;
> while(true) {
> if (j > 3)
> ret(j); // leave loop, and A
> else
> j = inc(j); // continue loop
> }
> }
>
> Calling a sequel like 'ret' is always a tail call, because it never returns
> to the caller, it returns elsewhere. In
> that sense, it is a generalized jump.
Yes, this exact technique is used by Smalltalk programmers
Allen_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss