explicit return from a block
Lukas Renggli
renggli at gmail.com
Tue Jun 27 11:02:09 UTC 2006
> Implement
>
> BlockClosure>>valueWithExit
> ^self value: [^nil]
In the visitors of Pier I use a similar pattern to jump to certain
states in the visitor. In Scheme this pattern is commonly done using
continuations, but since I always jump upwards the stack it is more
efficient to use blocks in Squeak.
Object>>withEscaper: aBlock
^ aBlock value: [ :value | ^ value ]
Then you can then do something like:
self withEscaper: [ :break |
aCollection do: [ :each |
self withEscaper: [ :continue |
....
... ifTrue: [ break value: result1 ].
... ifFalse: [ continue value: result2 ].
.... ] ]
Cheers,
Lukas
--
Lukas Renggli
http://www.lukas-renggli.ch
More information about the Squeak-dev
mailing list
|