Defining Runtime CHR Constraints

I am trying to write a program that generates new runtime restrictions in SWI-Prolog. is_true([A,means,B])designed to create another run-time constraint:

:- use_module(library(chr)).
:- chr_constraint is_true/1.

is_true([A,means,B]) ==> (is_true(A) ==> is_true(B),writeln('asserted')).
is_true([[A,is,true],means,[A,is,not,false]]).
is_true([something,is,true]).

But when I print these requests, the restriction is_trueseems to have no effect. is_true([something, is, not, false])does not return true:

?- is_true([something,is,true]).
true .

?- is_true([something,is,not,false]).
is_true([something, is, not, false]).

Closing a constraint in the console does not seem to have any effect:

?- asserta(is_true(A>B)==>(is_true(B<A),writeln("asserted"))).
true.

?- is_true(4>3).
is_true(4>3).

Is there any other way to define new runtime CHR restrictions?

+4
source share
1 answer

, is_true/2. assertz/1. , .

:

:- use_module(library(chr)).
:- chr_constraint is_true/1.

is_true(A) ==> is_true(A,B) | is_true(B).
is_true([A,means,B]) ==> assertz(is_true(A,B)).
is_true([],[]).

:

̀?- is_true([[A,implies,B],means,[A,means,B]]).
is_true([[A, implies, B], means, [A, means, B]]).

?- is_true([A>B,implies,B<A]).
is_true([A>B, means, B<A]),
is_true([A>B, implies, B<A]).

?- is_true(A>B).
is_true(B<A),
is_true(A>B).
0

Source: https://habr.com/ru/post/1683595/


All Articles