[Newbies] fromString: method

Davide Arrigo davide.arrigo at gmail.com
Sat May 24 11:06:22 UTC 2008


..........
> >
> > |s b|
> >
> >   s := '[:a :b | (a squared + b squared) sqrt ]'.
> >   b := (Block fromString:s).
> >   Transcript showCR:(b value:3 value:4)
> >
> > I need to get a Block of code from an input field  like TextMorph in a
> > GUI. I haven't found nothing like this in my squeak-dev image 3.10. Is
> > there another way to obtain am evaluable Block of code from a string?
> >
>
>
>         | s b |
>         s := '[:a :b | (a squared + b squared) sqrt ]'.
>         b := Compiler evaluate: s.
>         Transcript show: (b value: 3 value: 4); cr.
>
>  This will work for any expression in a String, not just blocks.
>
>  - Bert -
Great!! many thanks Bert it work fine.
Best regards
-- 
--------------------------
Davide Arrigo


More information about the Beginners mailing list