[squeak-dev] Problem with variable capture in blocks or ? #7532

Ken Causey ken at kencausey.com
Sun May 16 19:35:27 UTC 2010


Well, it's nothing new but this one has stumped me:

http://bugs.squeak.org/view.php?id=7532

Initially I (and Frank) thought the reporter was mistaken until we
understood that the problem shows up when you execute the main code all
in one do-it.  I've since modified the original report to make this
clearer.

So here it is:

a := 4.
b := [ :a | a ].
c := b value: a.

If you SELECT ALL OF THIS AND EXECUTE IT ALL AT ONE TIME (crucial
detail). The result is that a is 4, b is a BlockClosure, and c is a
BlockClosure not 4 as expected. Execute each statement separately and c
is 4.

Alternately, from a suggestion from jmckeon, if you specify a different
symbol for the block argument:

a := 4.
b := [ :d | d ].
c := b value: a.

when executed all at one time works as you would expect: a is 4, b is a
BlockClosure, and c is 4. (and d is nil)

So what's up?

Ken




More information about the Squeak-dev mailing list