【发布时间】:2017-08-12 23:12:25
【问题描述】:
我正在尝试在 SWI-Prolog 中编写一个在运行时生成新约束的程序。 is_true([A,means,B]) 旨在在运行时生成另一个约束:
:- 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]).
但是当我输入这些查询时,is_true 约束似乎没有任何效果。 is_true([something, is, not, false]) 不返回true:
?- is_true([something,is,true]).
true .
?- is_true([something,is,not,false]).
is_true([something, is, not, false]).
在控制台中断言约束似乎也没有效果:
?- asserta(is_true(A>B)==>(is_true(B<A),writeln("asserted"))).
true.
?- is_true(4>3).
is_true(4>3).
还有其他方法可以在运行时定义新的 CHR 约束吗?
【问题讨论】:
标签: swi-prolog constraint-handling-rules