[new to smalltalk] confusing problem: BlockContext >> cannot return

Marcus Denker denker at iam.unibe.ch
Wed Nov 24 17:02:33 UTC 2004


Am 24.11.2004 um 17:52 schrieb Herbert König:

> "-----Start Workspace"
>
> "This example string is to be converted into an object"
> str := 'G      0.000     38.199    1    2    68150.071    97542.712'.
>
> "As several types of strings have to be converted into different
> objects I feed them into a kind of method dictionary: to avoid a
> procedural case statement"
>
> dict := Dictionary new.
> dict   add: 'G' -> ([ :aLine | ^ Random new.]);
>


keep in mind that a return in a block will return from the method that 
the
Block was defined in, not the block.

Blocks return the value of the last expression of that block. So you 
need to just
do

   dict   add: 'G' -> ([ :aLine | Random new.]);


    Marcus



More information about the Squeak-dev mailing list