[Q] Block closures syntax

Joern Eyrich Joern.Eyrich at syngenio.de
Fri May 10 00:57:30 UTC 2002


Martin Drautzburg wrote:
> 
> I understand that squeak does not have true block closures, right ?
> But then I was pleased to see that the following
> 
> |y|
> Foo := [:x|
>         y ifNil: [y:=0].
>         y := x + y.
>         Transcript show: y; cr.
> ]
> Foo value:1.
> 
> does maintain the value of y and prints increasing values, even though
>         Transcript show: y asString;cr.
> prints nil.
> 
> Now if that is not a block closure, what else could one
> possibly ask from a block closure ? Can someone post an example ?

arr _ (1 to: 5) collect: [ :i | [i]].
arr do: [ :a | Transcript show: (a value printString); cr ]

prints 1 2 3 4 5 with closures, 5 5 5 5 5 in Squeak 

In this particular case you can workaround with:
arr _ (1 to: 5) collect: [ :i | [i] fixTemps ].

Here's a thread about this in the list archive:
http://aspn.activestate.com/ASPN/Mail/Message/squeak/538190

If you'd like to know more about what is going on "behind the scenes", you can read up on BlockContexts here:
http://coweb.cc.gatech.edu:8888/squeakbook/uploads/rowledge-final.pdf
http://users.ipa.net/~dwighth/smalltalk/bluebook/bluebook_imp_toc.html

Joern



More information about the Squeak-dev mailing list