Blocks and it's temp vars
Randal L. Schwartz
merlyn at stonehenge.com
Sat Dec 8 19:23:49 UTC 2007
[copied from Seaside list, where this was asked and answered as follows]
>>>>> "Sebastian" == Sebastian Sastre <ssastre at seaswork.com> writes:
Sebastian> At first I was suspecting about the #fixCallbackTemps but the block
Sebastian> was already malformed when reach that point. Investigating about this I'm
Sebastian> surprised to found that it's related to Squeak being unable to do properly
Sebastian> this smalltalk code:
Sebastian> stuff := #(foo bar).
Sebastian> results := OrderedCollection new.
Sebastian> 1 to: 2 do:[:i|
Sebastian> results add: [Transcript cr; nextPutAll: (stuff at:
Sebastian> i);flush]].
Sebastian> results do:[:e| e value]
I believe that this is a place where you need the fixTemps call on the block.
Did you try this as:
1 to: 2 do: [ :i |
results add: [
Transcript cr;
nextPutAll: (stuff at: Sebastian> i);flush
] fixTemps
].
As in, notice the difference between:
((1 to: 3) collect: [:i | [i]]) collect: [:aBlock | aBlock value]
=> #(3 3 3)
and
((1 to: 3) collect: [:i | [i] fixTemps]) collect: [:aBlock | aBlock value]
=> #(1 2 3)
--
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
mailing list
|