[Newbies] How can I create a script from within a script?

Bert Freudenberg bert at freudenbergs.de
Mon Feb 28 18:15:45 UTC 2011


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 -



More information about the Beginners mailing list