Full Closures - when do they close?

Robert Withers withers at vnet.net
Mon Jan 31 06:01:11 UTC 2000


yes it is close isn't it.  ;-)  I had no idea about #fixTemps.  This
second example has me in knots again.  I would think that foo would have
seperate bindings, in a full closure system, in the two different
blocks.

Stephan Rudlof wrote:
> 
> Vassily,
> 
> thank you. You have a deep understanding of this - Smalltalk version
> specific - stuff.

[snip]

> Just to check understanding of binding levels:
> 
> Method
>    | foo |
>    ^Array
>      with: [:arg | foo := arg]
>      with: [foo]
> 
> Squeak BlockContexts:           - 'foo' is on the same level as 'arg',
> Real BlockClosures:             - 'foo' is on another level as 'arg'.

The real BlockClosures example here is the one that threw me.  I would
think there would be three bindings of foo here and only two bindings
when the Array is returned.

So let me construct an example:
Method
  |array foo|
  foo := 10.
  array := Array with: [:arg | foo := arg] with: nil.
  foo := 20.
  array at: 2 put: [foo].
  ^array

"Before the return..."
{foo}-->20
{array}--> [1, 2]
  {array at: 1}--> {block}
                     |
                    {foo}--> 10  "arg doesn't have a binding yet

  {array at: 2}--> {block}
                     |
                    {foo}--> 20


Is this not our picture?  Does it have anything to do with foo on the
lhs in the first block?  


thanks,
Rob

[snip]

> > > Is it correct to say
> > >       aBlockContext fixTemps
> > > in Squeak behaves like a BlockClosure in VW?
> >
> > Great question!
> >
> > No.  One of the examples I gave in this thread:
> >
> >   | foo |
> >   ^Array
> >     with: [:arg | foo := arg]
> >     with: [foo]
> >

[snip]

> > "i" and the example works.  #fixTemps copies a little too much though--the
> > whole environment frame of the containing method, including variables such
> > as "foo" in the second example.  If you add #fixTemps to the example above,
> > blocks would use separate bindings for "foo".  Because closures do not copy
> > bindings (at least conceptually), the behaviour is different.
> >





More information about the Squeak-dev mailing list