|
[NEXT] [PREV]
HANDBOOK
/ LANGUAGE REFERENCE MANUAL
/Predicates |
||||||||||||
|
Gentle
Applications Concepts Examples Handbook Support Download
|
PredicateDecl =
Category Ident Signature Rules .
Category = "'nonterm'" | "'token'" | "'action'" | "'condition'" | "'choice'" | "'sweep'" . Signature = ["(" [ParamSpec{ "," ParamSpec}] ["->"[ParamSpec{ "," ParamSpec}]]")"] . Rules = {Head ":" Body "."} | {"'rule'" Head [":"] Body ["."]} . Head = Ident ["(" [Pattern{ "," Pattern}] ["->" [Expression{ "," Expression}]] ")"] . Body = {Member} [CostSpec] CostSpec = "$" Number .
Predicate DeclarationsA predicate declaration of the form
introduces a predicate p of category Category with n input parameters of types T1, ..., Tn, and with m output parameters of types S1, ..., Sm. A predicate may be used in a predicate invocation. A predicate that is invoked with input values Tau1, ..., Taun is elaborated as follows. If no rule is applicable, the invocation fails. Otherwise, a rule is selected and elaborated, yielding output values Sigma1, ..., Sigman, and the invocation succeeds.
RulesA rule has the form
For given input values Tau1, ..., Taun, the rule is elaborated as follows. Let V1, ..., Vnin be the variables appearing in P1, ..., Pn, and W1, ..., Wnout the variables appearing in E1, ..., Em. If the input values Tau1, ..., Taun do not match the patterns P1, ..., Pn, the rule is not applicable. Otherwise, the variables V1, ..., Vnin are defined. Then the members M1 ... Mk are elaborated. If one of the members fails, the rule is not applicable. Otherwise, the variables W1, ..., Wnout are defined. The expressions E1 ... Em are evaluated, yielding output values Sigma1, ..., Sigmam. A variable that appears in a pattern is said to be defined. A variable that appears in an expression is said to be applied. Each applied variable must be a defined variable. Variables that are applied in a member Mi must be defined by one of the patterns P1, ..., Pn or in a member Mj that appears to the left of Mi . A defined variable cannot be redefined.
|