A guard is a CPN ML Boolean expression that evaluates to
Before a guard has been added, the default text for the inscription is
- a Boolean expression or
- a list of Boolean expressions:
[b-exp1, b-exp2, ..., b-expn]
The latter corresponds to
b-exp1 andalso b-exp2 andalso ... bexpn, but is preferred as it gives the simulator more opportunities to bind the variables. Using a list of expressions does not necessarily have lazy evaluation like
andalso as the simulator may find more efficient ways of evaluation.
Guards are used for tests on input arc inscription variables (enabling restrictions), typically using one or more of the following syntactical elements:
Binding variables in guards
Variables that are not found in input arc inscriptions can, in some cases, be bound in the guard.
In this example, the variable
i is not on any input arcs, but it is bound to the value of the variable
j in the guard.
Guards are not allowed to have side effects and cannot:
- Contain input/output or
- Update or use reference variables.
- Use the
- Use the
These restrictions are currently not checked by CPN Tools, and the system may malfunction if the restrictions are violated.
Each expression used in a guard must be a Boolean expression, evaluating to
false. Thus the following example is legal because each variable binding is either true or not true:
[if a=3 then b=4 else c=5]
The following example is not legal because the
else clauses evaluate to integers:
[if a=3 then 4 else 5]