If I create a text string which contains squeak code, how can I execute it from within a script?

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

If I create a text string which contains squeak code, how can I execute it from within a script?

Steve Thomas
Folks,

I am trying to create a project where kids can enter their own "Connector" functions.

So what I want to do is given a connector connected to two text boxes (one Enhanced Text, so I can execute a script when they hit <CR> or on <focus loss>).
I have a string variable defined for the connector, in which the kids can enter a function like ( D = S + 25)
Where D maps to DestinationPlayer and S maps to SourcePlayer.

Ideally I would like to generate the below script and execute it:

doIt
self getDestinationPlayer setNumericValue: self getSourcePlayer getNumericValue + 25


Need some squeak coding help on this.  I guess specifically, assuming I can figure out how to create a string with the correct code ...
How do I "do it" to the string?

Thanks,
Stephen

_______________________________________________
squeakland mailing list
[hidden email]
http://lists.squeakland.org/mailman/listinfo/squeakland

ConnectorMath.001.pr (126K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [etoys-dev] If I create a text string which contains squeak code, how can I execute it from within a script?

Bert Freudenberg

On 01.02.2012, at 13:24, Steve Thomas wrote:

> Folks,
>
> I am trying to create a project where kids can enter their own "Connector" functions.
>
> So what I want to do is given a connector connected to two text boxes (one Enhanced Text, so I can execute a script when they hit <CR> or on <focus loss>).
> I have a string variable defined for the connector, in which the kids can enter a function like ( D = S + 25)
> Where D maps to DestinationPlayer and S maps to SourcePlayer.
>
> Ideally I would like to generate the below script and execute it:
>
> doIt
> self getDestinationPlayer setNumericValue: self getSourcePlayer getNumericValue + 25
>
>
> Need some squeak coding help on this.  I guess specifically, assuming I can figure out how to create a string with the correct code ...
> How do I "do it" to the string?


Compiler evaluate: '3 + 4'

- Bert -


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

Re: [etoys-dev] If I create a text string which contains squeak code, how can I execute it from within a script?

Karl Ramberg
In reply to this post by Steve Thomas
On Wed, Feb 1, 2012 at 10:24 PM, Steve Thomas <[hidden email]> wrote:

> Folks,
>
> I am trying to create a project where kids can enter their own "Connector"
> functions.
>
> So what I want to do is given a connector connected to two text boxes (one
> Enhanced Text, so I can execute a script when they hit <CR> or on <focus
> loss>).
> I have a string variable defined for the connector, in which the kids can
> enter a function like ( D = S + 25)
> Where D maps to DestinationPlayer and S maps to SourcePlayer.
>
> Ideally I would like to generate the below script and execute it:
>
> doIt
> self getDestinationPlayer setNumericValue: self getSourcePlayer
> getNumericValue + 25
>
>
>
> Need some squeak coding help on this.  I guess specifically, assuming I can
> figure out how to create a string with the correct code ...
> How do I "do it" to the string?
>
> Thanks,
> Stephen
>
> _____

I have also wanted a enhanced workspace where one evaluate a line with
enter/return.
Workspaces create textual references to dropped morphs, see workspace
window menus.
That way you can keep track of many morphs on screen.
Evaluation is done by select and Ctr l+ D

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

Re: [etoys-dev] If I create a text string which contains squeak code, how can I execute it from within a script?

Bert Freudenberg
In reply to this post by Bert Freudenberg

On 01.02.2012, at 13:53, Bert Freudenberg wrote:

>
> On 01.02.2012, at 13:24, Steve Thomas wrote:
>
>> Folks,
>>
>> I am trying to create a project where kids can enter their own "Connector" functions.
>>
>> So what I want to do is given a connector connected to two text boxes (one Enhanced Text, so I can execute a script when they hit <CR> or on <focus loss>).
>> I have a string variable defined for the connector, in which the kids can enter a function like ( D = S + 25)
>> Where D maps to DestinationPlayer and S maps to SourcePlayer.
>>
>> Ideally I would like to generate the below script and execute it:
>>
>> doIt
>> self getDestinationPlayer setNumericValue: self getSourcePlayer getNumericValue + 25
>>
>>
>> Need some squeak coding help on this.  I guess specifically, assuming I can figure out how to create a string with the correct code ...
>> How do I "do it" to the string?
>
>
> Compiler evaluate: '3 + 4'
>
> - Bert -

... and to be a bit less brief, a simple way to introduce variables is compiling a block:

        (Compiler evaluate: '[:a :b | a + b ]') value: 3 value: 4

Also see attached your project, enhanced.

[I'd get rid of the D and S and the assignment, just have the kids enter "x + 25". Makes the veal code simpler. Also, watch out for "3 + 4 * 5" having not the same result as when using Etoys tiles. The way around that would be to implement an actual grammar for your functions, not just re-use the Smalltalk grammar]

- Bert -


_______________________________________________
squeakland mailing list
[hidden email]
http://lists.squeakland.org/mailman/listinfo/squeakland

ConnectorMath.002.pr (67K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [etoys-dev] If I create a text string which contains squeak code, how can I execute it from within a script?

Steve Thomas
Thanks Bert!!!

... and to be a bit less brief, a simple way to introduce variables is compiling a block:

       (Compiler evaluate: '[:a :b | a + b ]') value: 3 value: 4
Also see attached your project, enhanced.
 
[I'd get rid of the D and S and the assignment, just have the kids enter "x + 25". Makes the veal code simpler. Also, watch out for "3 + 4 * 5" having not the same result as when using Etoys tiles. The way around that would be to implement an actual grammar for your functions, not just re-use the Smalltalk grammar]

Good idea.  I made the changes and am playing around with Compiler evaluate.



_______________________________________________
squeakland mailing list
[hidden email]
http://lists.squeakland.org/mailman/listinfo/squeakland