:- import memberchk/2 from lists.
:- import merge_answer_store/1,
get_chr_store/1,
set_chr_store/1,
get_chr_answer_store/2
from chr.
:- table tabled_p/2.
:- constraints leq/2, project/1.
... /* other CHR rules */
project(L) \ leq(X,Y) <=>
( var(X), \+ memberchk(X,L)
; var(Y), \+ memberchk(Y,L)
) | true.
project(_) <=> true.
p(X) :-
tabled_p(X1,AnswerStore),
merge_answer_store(AnswerStore),
X1 = X.
tabled_p(X,AnswerStore) :-
get_chr_store(CallStore),
set_chr_store(_EmptyStore)
orig_p(X),
project([X]),
get_chr_answer_store(chrmod,AnswerStore),
set_chr_store(CallStore).
orig_p(X) :-
... /* original body of p/1 */.
The example in the following subsection shows projection in a full application.