Friday, March 30, 2012

Getting Started: ELENA DSA Script, part 2

In the previous post I showed how to create a pure dynamic code combining different group objects with each other without actually writing the code. So Hello world program will look like this:

&eval &nil sys'dynamics'castvariable 
  &nil sys'dynamics'batch
     &sys'vm'routines'ereturnprop "Hello World" &wrap 
        ~sys'dynamics'group_member ^append
     &write &nil 'program'output &wrap 
       ~sys'dynamics'group_member ^append
     ~sys'dynamics'group_member ^append 
  &get &nil 'program'input &wrap
  ~sys'dynamics'group_member ^append 
&wrap &nil ^eval

which is equivalent to the following ELENA code:

__wrap(__eval, __cast(
         __batch(__wrap(sys'vm'routines'ereturnprop, "Hello World"), 
                 __wrap(__write, 'program'output)),
         __wrap(__get, 'program'input))) eval.

In this example we use another group object - cast. A cast collection repeats a received message for every its member.

Inline script is not intended for direct usage so we should use a grammar. We could use a grammar script provided in the language - default.vl2

Let's start VM terminal


Now we may load existing grammar scripts with a command - c


Now let's start a VM


Our program consists of two actions - printing a message and waiting for any key. So let's assign a variable output and input to these actions

output = [ sys'vm'routines'ereturnprop->"Hello world" 
            write->'program'output ]
input = get -> program'input

And combine them into the program

action = < output input >
program = eval->action

So now we could execute our program


As you see with a help of the grammar our program becomes much simpler. The grammar is quite simple

a -> b 

creates a wrap,

[ ... ] 

creates a batch,

< ... > 

create a cast

variable =  

assigns the expression to the variable, and


sends a message verb to obj

No comments:

Post a Comment