blocks (was: Caper needs Self Help)
mike_ekim at yahoo.com
Thu Nov 20 09:17:16 UTC 2003
--- In self-interest at yahoogroups.com, Jecel Assumpcao Jr <jecel at m...>
> On Tuesday 18 November 2003 21:48, Mike Austin wrote:
> > A huge complication? Aren't block closure's just anonymous
> > (which are objects) with their proto set to their enclosing
> > environment? I thought it was something like this in self.
> It does look simple when you put it that way.
> But what is "their enclosing environment"?
> A) The method object in which the block literal is stored?
> B) The closure/context/activation object cloned from A in which
> "push literal" bytecode is actually executed?
B) The activation object, or method-instance for another term
> And who are we talking about in "their proto (parent, actually) set
> 1) The block literal object?
> 2) The result of referencing 1 with a "push literal"?
> 3) The block closure resulting from sending 'value' to 2?
1) The block literal object
> In Self, we set the parent of 3 to point to B and that is far more
> complicated to arrange than I would like. Sadly, simplifying this
> normally leads to a loss of important functionality (like being
> send 'value' more than once to one of your block arguments or
> invocation of blocks).
Although Io handles locals a bit different, it is essentially the
same idea when I do this:
myObject = Object clone do (
` add = method ( n,
` ` return block( x, return n + x )
a = myObject add( 10 )
b = myObject add( 20 )
write( a( 10 ), "\n" )
write( b( 10 ), "\n" )
> io closure_test.io
The returned block's proto is set to the new "Locals" instance that
is created when calling add. It works simply, and beautifully.
More information about the Self-interest