How can I create a script from within a script?

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

How can I create a script from within a script?

Steve Thomas
I am playing with the idea of creating a scripting language for kids.

So given the script below p1 is being set to an object/Player named Ellipse:

script2
    | t1 t2 p1 |
    p1 := Ellipse
    t1 := 'forward'.
    t2 := 5

How can I get it to "do/execute": p1 forward: 5

Stephen

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

Re: How can I create a script from within a script?

Gary Dunn-2

The direct answer is thay it depends on how you design tour interpreter. In Squeak we fiddle in a Workspace but that is not an interpreter. We invoke the interpreter with do it or evaluate. In other scripting languages the script is a file read by the interpreter.

In a smalltalk method, a statement begins with an object which receives messages represented by the remaining items in the statement. Your Ellipse would be such an object and it would have a method called forward.

The less direct answer is a comment. No need to create a scripting language for kids because smalltalk is already that tool. Please read up on Squeaks history, and its creator Alan Kay. Start with Wikipedia. Then dig into Squeaks morphic interface  which removes most of the abstraction of scripting. Then look at eToys. It's all there, a rich and delightful world for children of all ages.

On Feb 28, 2011 6:31 AM, "Steve Thomas" <[hidden email]> wrote:

I am playing with the idea of creating a scripting language for kids.

So given the script below p1 is being set to an object/Player named Ellipse:

script2
    | t1 t2 p1 |
    p1 := Ellipse
    t1 := 'forward'.
    t2 := 5

How can I get it to "do/execute": p1 forward: 5

Stephen

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners


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

Re: How can I create a script from within a script?

Alex Schenkman
Take a look at: http://rmod.lille.inria.fr/botsinc

On Monday, February 28, 2011 at 6:05 PM, Gary Dunn wrote:

The direct answer is thay it depends on how you design tour interpreter. In Squeak we fiddle in a Workspace but that is not an interpreter. We invoke the interpreter with do it or evaluate. In other scripting languages the script is a file read by the interpreter.

In a smalltalk method, a statement begins with an object which receives messages represented by the remaining items in the statement. Your Ellipse would be such an object and it would have a method called forward.

The less direct answer is a comment. No need to create a scripting language for kids because smalltalk is already that tool. Please read up on Squeaks history, and its creator Alan Kay. Start with Wikipedia. Then dig into Squeaks morphic interface  which removes most of the abstraction of scripting. Then look at eToys. It's all there, a rich and delightful world for children of all ages.

On Feb 28, 2011 6:31 AM, "Steve Thomas" <[hidden email]> wrote:

I am playing with the idea of creating a scripting language for kids.

So given the script below p1 is being set to an object/Player named Ellipse:

script2
    | t1 t2 p1 |
    p1 := Ellipse
    t1 := 'forward'.
    t2 := 5

How can I get it to "do/execute": p1 forward: 5

Stephen

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners


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

Re: How can I create a script from within a script?

Bert Freudenberg
In reply to this post by Steve Thomas
On 28.02.2011, at 08:31, Steve Thomas wrote:

> I am playing with the idea of creating a scripting language for kids.

One way would be to just generate Smalltalk code that does what you want, and compile it into a new method. But writing your own interpreter as you suggest below would work, too.

The first is more efficient, the latter more flexible. For example, Etoys generates Smalltalk code, Scratch interprets. Etoys is restricted to Smalltalk semantics. Scratch extends the semantics, e.g. for the "wait" tile.

It's also possible to combine efficiency with extended semantics, like Tweak or Croquet do. But that's hardly a beginner's project :)

> So given the script below p1 is being set to an object/Player named Ellipse:
>
> script2
>     | t1 t2 p1 |
>     p1 := Ellipse
>     t1 := 'forward'.
>     t2 := 5
>
> How can I get it to "do/execute": p1 forward: 5

To execute a method given its name, use "perform". E.g.

        selector := (t1, ':') asSymbol. "add the colon, convert to Symbol"
        p1 perform: selector with: t2

- Bert -

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners