@@ -461,15 +461,62 @@ The `constraint` directive gives control on the hypothetical part of the
461
461
program that is kept by the suspended goal and lets one express constraint
462
462
handling rules.
463
463
464
- A "clique" of related predicates is declared with
464
+ A new constraint can be declared with the following syntax:
465
465
``` prolog
466
- constraint foo bar ... {
466
+ constraint p1 p2 p3 ?- foo bar {
467
+ rule (Ctx ?- foo Arg1) | ... <=> (Ctx => bar Arg1)
468
+ }
469
+ ```
470
+
471
+ > [ !IMPORTANT]
472
+ > When a suspended goal (via ` declare_constraint ` ) is resumed, only the rules
473
+ implementing the symbols passed in the head of the constraint are kept.
474
+
475
+ In our example, only the rules for ` p1, p2, p3, foo ` and ` bar ` are kept.
476
+ Therefore, if just before the suspension of the goal ` foo x ` a rule like ` p4 `
477
+ exists, this rule will not be filtered out from the rules in the suspended goal.
478
+
479
+ The symbol ` ?- ` in the head of a constraint is used to separate two lists of
480
+ predicate names, the former list represents predicate names to be loaded as a
481
+ predicate filter to load the wanted rules as hypotheses in the context, whereas
482
+ the latter list contains predicates to be used in the new premises to be solved.
483
+
484
+ In the example above, the rules implementing ` p1 ` , ` p2 ` and ` p3 ` are filtered in
485
+ in the suspended goal, that is, they are loaded into ` Ctx ` . Therefore, when
486
+ solving the goal ` Ctx => bar Arg1 ` all the rules for these three predicates are
487
+ charged.
488
+
489
+ The list of predicate names after the ` ?- ` should form a "clique", a set of
490
+ symbols disjoint from all the other cliques in the constraint store. If two
491
+ overlapping cliques are detected, the fatal error * overlapping constraint
492
+ cliques* is raised. The overlapping check is not applied to the list of
493
+ hypotheses symbols before ` ?- ` , that is, in the case of two constraints declared
494
+ on two same cliques ` c ` with different hypothesis ` h1 ` and ` h2 ` , then the two
495
+ set of hypotheses are merged and added to the clique ` c ` .
496
+
497
+ For example, if we keep the example above, the following code snipped would
498
+ correctly extend the previous constraint:
499
+
500
+ ```
501
+ constraint p4 ?- foo bar {
467
502
rule ...
468
503
}
469
504
```
470
- The effect is that whenever a goal about ` foo ` or ` bar `
471
- is suspended (via ` declare_constraint ` ) only its hypothetical
472
- clauses about ` foo ` or ` bar ` are kept.
505
+
506
+ From now on, all the goals suspended on the predicates ` foo ` and ` bar ` will see
507
+ in their contexts the four all the rules implementing the predicates `p1, p2,
508
+ p3, p4` = $\{$ ` p1,p2,p3` $\} \cup \{$ ` p4`$\} $.
509
+
510
+ > [ !NOTE]
511
+ > If the list of predicate names before ` ?- ` is empty, then the ` ?- ` can be avoided
512
+
513
+ Example: ` constraint foo bar { ... } ` . In this case the new suspended goals
514
+ talking about ` foo ` and ` bar ` will consider the rules for the predicates `p1,
515
+ p2, p3` = $\{$ ` p1,p2,p3`$\} \cup \varnothing$.
516
+
517
+ Finally ` constraint foo bax { ... }. ` raise the overlapping clique error, since
518
+ this constraint set intersect with another clique, i.e. $\{ $` foo,bax ` $\} \cap
519
+ \{ $` foo, bar ` $\} \neq \varnothing$.
473
520
474
521
When one or more goals are suspended on lists of unification
475
522
variables with a non-empty intersection,
@@ -519,7 +566,8 @@ Failure
519
566
#### Syntax
520
567
Here ` + ` means one or more, ` * ` zero or more
521
568
```
522
- CONSTRAINT ::= constraint CLIQUE { RULE* }
569
+ CTX_FILTER ::= CLIQUE ?-
570
+ CONSTRAINT ::= constraint CTX_FILTER? CLIQUE { RULE* }
523
571
CLIQUE ::= NAME+
524
572
RULE ::= rule TO-MATCH TO-REMOVE GUARD TO-ADD .
525
573
TO-MATCH ::= SEQUENT*
0 commit comments