Instead of using the key word def we use rel, fun and act as in the examples below.
The arguments of relation and action declarations are moded types. If the mode is missing it defaults to !. The arguments of a function declaration are types - modes are not required as the arguments are always ground.
By listing multiple type declarations for a single relation, function or action we are actually declaring an intersection type as below (for a user declared version of append).
Below are some examples of using code types as arguments of declarations of other code types.
We can also declare a special case of rel for dynamic relations using dyn as below.
These dynamic relations simply store ground facts in the Belief Store and the intention is to be able to query thse facts and so, for these declarations we have types (not moded types) as the implicit mode is ? as opposed to ! for functions.
A special case of dynamic relation is what we call “global values” - they can either be of type int or num. The declaration also initializes the value. The current value can be accessed using a $ prefix and the value can be modified by using the operators :=, +:= and -:= as in the examples below.
In declaring relations and functions (typically that depend on the belief store) we can use mrel and mfun instead. The m stands for memoization. Please refer to the section entitled “Automatic Memoization of Functions and Relations” in the reference manual for details.