What rules to follow to avoid block-closure problems?
Randal L. Schwartz
merlyn at stonehenge.com
Mon Jan 14 01:29:23 UTC 2008
>>>>> "Amos" == Amos <aaamos at gmail.com> writes:
>> > Have you got an example handy?
Amos> Interesting. The example on that page works just fine in VW (which is
Amos> what I'm used to), but not in Squeak. So... probably a dumb question,
Amos> but are some Squeakers seriously willing to live with that...?
But this works fine as well in modern VMs:
blocks := (1 to: 10) collect: [:each | [each] fixTemps].
blocks first value.
The point is that BlockContext>>#fixTemps is (a) a hack (doesn't work EVERY
time) and (b) expensive, so it isn't sent every time, even though that
probably wouldn't hurt.
For now, it's up to you to know when you have a block that might need closure
treatment, which is simple enough to determine by humans: do you need the
values of externally defined temps to be cloned and disconnected from the
surrounding code? In this case, the answer was "yes", because we wanted each
block to have its own "each" temp.
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
More information about the Squeak-dev