[self-interest] blocks and closures

Jecel Assumpcao Jr jecel at merlintec.com
Wed Apr 9 23:41:14 UTC 2003


On Wednesday 09 April 2003 17:28, Steve Dekorte wrote:
> Is there any difference between a Self/Smalltalk block and a LISP
> closure?

That depends on what you mean by "Self block". You might be thinking 
about any of the following three objects:

 1) what is translated from the "[...]" source text and stored in the 
literal vector of some method. When a "push literal" bytecode is 
executed which refers to this object, a new object of type 2 is 
actually created and pushed on the stack. Most Smalltalks don't bother 
with this and actually compile the "[...]" to a sequence of special 
bytecodes that will explicitly create the type 2 object.

 2) this is an object that holds on to the execution context in which it 
is created in addition to the information originally in the type 1 
object. It also understands messages like 'whileTrue:', 'loop' and 
'value'.

 3) this is very much like a regular method context created as a result 
of sending 'value' (or its brothers) to a type 2 object, but it is set 
to inherit from the execution context saved in the type 2 object and 
not from its receiver (which would be the type 2 object itself, in this 
case).

So the answer to your question is 1) no, 2) essentially the same thing, 
3) no - this would be like a Lisp application of (to?) a closure.

Are we having fun yet, or should we move on to continuations? ;-)
-- Jecel



More information about the Self-interest mailing list