|
I've run into a D5 problem with blocks that I'm having trouble getting
around. A simple illustrating example is this:
In a class named MyClass, I have the following method:
testOneDigitDivisorsOf: anInteger
| blockCollection |
blockCollection := OrderedCollection new.
1 to: 9 do: [:divisor |
blockCollection add: [:number | number \\ divisor == 0]].
^blockCollection collect: [:block | block value: anInteger].
Now I expected "MyClass new testOneDigitDivisorsOf: 63", for example, to
return a collection with true in slots 1, 3, 7 and 9, but all of its
elements are false. Substituting 60 for 63, however, gives an all-true
reply; apparently, the value 10 held by the variable "divisor" after the
to:do: has finished is used in all the blocks. I guess this may have
something to do with the lack of full block closures or something (my
understanding of these things is pretty incomplete). Any tips on how to work
around this problem?
|