[Newbies] fromString: method
Bert Freudenberg
bert at freudenbergs.de
Sat May 24 10:58:33 UTC 2008
On 24.05.2008, at 12:47, Davide Arrigo wrote:
> Hy all, I worder if there's something like this: Block fromString:
> aString in Squeak, like the example below taken from SmallTalk/X
> programmers guide.
>
> |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 -
More information about the Beginners
mailing list