The body of a rule is given by a sequence of members. A member is elaborated as follows.
A member of the form
p must be a predicate with n input parameters and m output parameters. Let T1, ..., Tn be the input types and S1, ..., Sm the output types. The expressions E1, ..., En appear on positions with types T1, ..., Tn, and the patterns P1, ..., Pm appear on positions with types S1, ..., Sm.
The expressions E1, ..., En are evaluated, yielding values Tau1, ..., Taun. p is invoked with these input values. If the invocation fails, the member M fails. If it succeeds, it yields output values Sigma1, ..., Sigmam. These values are matched against the patterns P1, ..., Pm. If the matching fails, the member M fails. Otherwise, the member succeeds and the variables appearing in P1, ..., Pm are defined.
A member of the form
The value of D is defined as the value of the expression E. If T is the type of D, E appears on a position with type T.
The context designator D may be of the form C, where C must be declared as a context variable. The type of the designator is the type of the context variable.
Example
NestingLevel <- NThis sets the value of the context variable NestingLevel to the value of the local variable N. |
|
A context designator may also have the form I ' F ; I must be a variable of the key type of a context table T. Entries of T must have a field F. The type of the designator is the type of the F.
Example
Let Lab be a local variable that refers to a table entry with a field Coordinate. Then Lab'Coordinate <- Locsets this field to the value of Loc. |
|
The value of the context designator D is matched against the pattern P. If this succeeds, the member succeeds and the variables appearing in P are defined. Otherwise, the member fails.
Examples
NestingLevel -> NThis defines the local variable N according to the current value of the context variable NestingLevel. Let Lab be a local variable that refers to a table entry with a field Coordinate. Then Lab'Coordinate -> Locdefines the local variable Loc according to the value of this field. |
|
It is a checked run-time error to access an undefined context designator.
The variable V is defined as a unique key of type T.
Example
Lab :: LabelThe value of the local variable Lab is the unique key of a newly created entry of table Label. |
|
A member of the form
A member of the form
The alternatives A1, ..., An are evaluated from left to right until one alternative Ai succeeds. Then M succeeds. If all alternatives fail, M fails.
An alternative Ai has the form Mi,1, ..., Mi,ni. These members are evaluated from left to right until one member fails. Then the alternative fails. If all members succeed, the alternative succeeds.
A variable that is defined in all alternatives A1, ..., An is defined by the alternative statement and may be used outside it. Such a variable must be defined with the same type in all alternatives.
A variable that is defined in one but not all alternatives is local to that alternative.