Does Smalltalk have a way to break out of a block?
Ned Konz
ned at bike-nomad.com
Wed May 30 02:18:18 UTC 2001
On Tuesday 29 May 2001 19:14, I wrote:
> So when the done flag is set, innerMethod1 returns and thereby breaks out
> of its while loop. Typically code can be re-factored so that this can be
> done. In your case, you have a multi-way conditional on string prefixes.
> This can be written:
>
> d _ Dictionary new
> at: 'ice:' put: [ :s | (s findTokens: 'ice:') first ];
> at: ':ELEVATION:' put: [ :s | params at: #elevation put: ((s findTokens:
> ':ELEVATION:') first)
Sorry, that was a premature send (I did the Squeak ctrl-Return, and my mailer
sent the partial message).
Anyway, what I was going to show is that the iteration of coll could be
modeled with a collect: that in some cases might collect nils. This could be
followed by a reject: to get rid of the nils.
And this would get rid of all the 'at: i' stuff in the sample (this isn't a
very Smalltalky way to do things).
The dictionary I was building above was an attempt to compress the source
code.
--
Ned Konz
currently: Stanwood, WA
email: ned at bike-nomad.com
homepage: http://bike-nomad.com
More information about the Squeak-dev
mailing list
|