Search code examples
booggie

How can I execute a script in a rule and pass a value back to a rule in booggie 2?


In booggie 2, how can I execute a script (programmed in Python) out of a rule and pass the script's return value to the rule?

Please note: The booggie-project does not exist anymore but led to the development of Soley Studio which covers the same functionality.


Solution

  • exec is the command to execute rules and scripts out of a rule. It is followed by parentheses containing a sequence composed of rules and scripts.

    There is a strict order in which the application sequence in a rule is executed, (cf. Is there a fixed order of how the right-hand side of a rule is executed in GrGen.NET?). exec is always the last statements that's executed (before return of course). Hence, we can't pass a variable from exec to eval. Therefore, variables resulting from the execution of scripts in exechave to assigned to node/edge-attributes within the exec statement. To do so, we use curly brackets and write the same code as we would in an eval statement.

    In the following example, a script is called that returns the highest value of three given values (a.value, b.value, c.value) and stores it a node's attribute (d.value).

        exec ((max_value) = getMaxValue(a.value, b.value, c.value) ;>
                {
                    d.value = max_value;
                }
            );