Can you give some basic examples about how to define global variables, assign values to them and then get the values from them?

Since I’m new to Spoofax, these basic instructions will help me a lot.
Thank you!

Asked by Hilal Cora on 24 January 2013 at 22:13

As far as I know you must use a dynamic rule to do global variables. You could define a rule like this:

set-global = ?(name,value) ; rules(get-global: name -> value)

Then you can set/get a global like:

<set-global> ("foo", "bar")
bar := <get-global> "foo"

The docs for dynamic rules are all encompassed in the paper about dynamic rules in spoofax. There an introduction to it in this paper:

A paper specifically about this feature is here:

Answered by Dobes Vandermeer on 24 January 2013 at 22:34

There is a dynamic rule variant that defines a global variable, using :=

rules(Foo := "bar");
bar := <Foo>

Note that these rules are evaluated when defined instead of when called:

rules( Number := <<debug> "evaluated"; !1> );
<debug> "number:";
<debug> <Number>



Origin of this dynamic rule variant:

Answered by Danny Groenewegen on 24 January 2013 at 23:38

Thanks for your answer.

Answered by Hilal Cora on 25 January 2013 at 08:12

Hi Hilal, maybe better to hit the mailing list with this question.

Answered by Dobes Vandermeer on 25 January 2013 at 21:05