fromString: method

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

fromString: method

Davide Arrigo
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?
Many thanks
--
--------------------------
Davide Arrigo
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: fromString: method

Bert Freudenberg
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 -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: fromString: method

Davide Arrigo
..........

> >
> > |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
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners