LPCIC / elpi

Embeddable Lambda Prolog Interpreter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CHR: add unique non instantiable key instead of [_]

FissoreD opened this issue · comments

[_] is used typically to retrieve all the goals suspended for a given predicate.
The use of [_] can lead to goal resolution issue if the _ is accidentally instantiated.
For example, the following code raise a failure:

pred p i:int.
pred trig.

% this extends the previous constraint
constraint p trig {
  rule \ trig (p A) <=> (false).
}

main :-
  % declare_constraint (p 4) [_], not (declare_constraint trig [_]).
  std.spy-do![declare_constraint (p 4) [_], not (declare_constraint trig [_])].

The premise with the spy-do! fails, whereas the same premise without the spy-do! succeeds

Thanks for opening the issue.
I think the desired solution is to use some constant, say the-key, instead of _, eg declare_constraint (p X) [X,the-key] to get it resumed when X materializes and combined via CHR rules with all the other constraints about X or about the-key.

| Discard -> [dummy_uvar_body]