- List of Backups
- View the diff.
- View the diff current.
- View the source.
- Go to Guards.
- 1 (2004-02-01 (Sun) 13:13:23)
- 2 (2004-02-02 (Mon) 12:52:33)
- 3 (2004-04-06 (Tue) 11:45:47)
- 4 (2004-04-21 (Wed) 13:48:35)
- 5 (2004-10-15 (Fri) 10:59:26)
- 6 (2004-10-22 (Fri) 09:52:20)
- 7 (2006-01-08 (Sun) 15:18:09)
- 8 (2006-03-14 (Tue) 14:33:50)
- 9 (2006-11-02 (Thu) 10:36:50)
- 10 (2006-11-02 (Thu) 10:36:50)
- 11 (2010-06-13 (Sun) 15:51:59)
- 12 (2015-05-17 (Sun) 20:34:13)
- 13 (2015-05-18 (Mon) 21:07:14)
- 14 (2017-03-02 (Thu) 03:32:49)
- 15 (2017-03-02 (Thu) 07:49:19)
*16 (2019-04-29 (Mon) 10:31:19)*- 17 (2019-04-29 (Mon) 16:49:44)

Guards specify applicability conditions of rewrite rules. The syntax of a rule with a guard is:

Head:-Guard|Body

where *Guard* is a multiset of **type constraints** of the form
*c*($*p*1, ..., $*p**n*).

Type constraints constrains the shapes of processes
(or the names of unary atoms)
received by the process contexts $*p*1, ..., $*p**n*.
The **type constraint name** *c* is drawn from a built-in set and specifies which kind of constraints is imposed.

A constraint of the form **uniq**($*p*1, ..., $*p**n*) is
also allowed. This is a control structure rather than a type constraint
and used to avoid infinite rule application (see below).

Here is an example rule with guard:

waitint(X), $p[X] :- int($p) | ok.

This can be abbreviated to

waitint($p) :- int($p) | ok.

and can be thought of representing the following infinite number of rules:

waitint(0) :- ok. waitint(1) :- ok. waitint(-1) :- ok. waitint(2) :- ok. waitint(-2) :- ok. ...

The following are examples of some type constraints that can be written in *Guard*:

- int($p) ... specifies that $p must be an integer atom.
- 4($p) ... specifies that $p must be a unary integer atom of value 4 (i.e., 4(X)).
- $p < $q ... specifies that $p and $q are integer atoms such that the value of $p is less than that of $q.
- $r = $p +. $q ... specifies that $p, $q, and $r are floating point number atoms such that the sum of the values of $p and $q is equal to the value of $r.

Each type constraint name (such as int or <) has its own mode of usage that specifies which of its arguments are input arguments. The effect of the constraint specified by a type constraint is enabled only after the shapes (or values) of its input arguments are all determined. For example, $r = $p + $q proceeds only when $p and $q are determined.

The same abbreviation scheme as defined for atoms
applies to type constraints when a process context name
$*p**k*
occurs exactly twice in the rule.
For example, **p($n) :- $n>$z, 0($z) | ok** can be abbreviated
to **p($n) :- $n>0 | ok**.

A process context constrained in *Guard*
is said to be a **typed process context**.

The following type constraints can be used in guards. The + (input) sign preceding a process context name means that the name should appear in the head, while the - (output) sign means that the name should not appear in the head.

- int(+$i)
- check if $i[X] is an integer.
- float(+$f)
- check if $f[X] is a floating-point number.
- unary(+$u)
- check if $u[X] is a unary atom. Note that
**int**and**float**are subtypes of**unary**. - ground(+$g)
- check if $g[X1,...,Xn] (n>0) is a connected graph whose free links are exactly X1,...,Xn. Note that
**unary**is a subtype of**ground**.

- '='(+$u,+$v)
- check if $u[X1,...,Xn] and $v[Y1,...,Yn] are connected graphs with the same structure.
- '\='(+$u,+$v)
- check if $u[X1,...,Xn] and $v[Y1,...,Ym] are connected graphs with different structures.
- '=='(+$u,+$v)
- check if $u[X] and $v[Y] are unary atoms with the same name.
- '\=='(+$u,+$v)
- check if $u[X] and $v[Y] are unary atoms with different names (if either of them are not unary, the check fails.)
- '<.'(+$float,+$float)
- float comparison; also:
**'>.'**,**'=<.'**,**'>=.'**,**'=:=.'**,**'=\=.'**. - '<'(+$int,+$int)
- integer comparison; also:
**'>'**,**'=<'**,**'>='**,**'=:='**,**'=\='**.

- '='(+$u,-$v)
- make sure that $u[X] and $v[Y] are unary atoms with the same name.
- '='(-$u,+$v)
- same as above.
- int(+$float,-$int)
- cast to int.
- float(+$int,-$float)
- cast to float.
- 345(-$int)
- defined for every integer (not only with 345).
- '-3.14'(-$float)
- defined for every float.
- '+'(+$int,+$int,-$int)
- integer operation; also:
**'-'**,**'*'**,**'/'**,**mod**. - '+.'(+$float,+$float,-$float)
- float operation; also:
**'-.'**,**'*.'**,**'/.'**.

A constraint of the form
**uniq**($*p*1, ..., $*p**n*)
succeeds if each $*p**k* is a *ground* structure
(connected graph with exactly one free link; see below)
and the rule has not
been applied to the tuple
$*p*1, ..., $*p**n*
before.

As a special case of *n*=0,
**uniq** succeeds if the rule in question has not been used
before. The **uniq**() test is a general tool for avoiding
infinite application of rules whose right-hand side is a
super(multi)set of the left-hand side.

- uniq(+$g1,...,+$gn)
- uniqueness constraint; checks if the rule has not been applied to the tuple $g1[X1], ..., $gn[Xn] (n>=0).