prolog语言中asserta,retract的使用
我用的是swi-prolog
不过我也用amzi!-prolog试过
这是其中的两句
here(kitchen).
move(Place):- retract(here(X)), asserta(here(Place)).
这是网上教程中的一个例子
我执行move(office).后,
错误提示如下:
ERROR: retract/1: No permission to modify static_procedure `here/1'
^ Exception: (8) retract(here(_G315)) ?
请高手指点一下
[解决办法]
我找到了,Visual Prolog专门对这个问题又说明
The asserta(Fact) predicate inserts a Fact in the matched internal facts database before any other stored facts for the corresponding predicate. The Fact must be a term belonging to the domain of an internal facts database. The asserta/1 applied to a single fact changes the existing instance of a fact to the specified one. See also assert/1 and assertz/1.
Notice that the combination of retract/1 and asserta/1 like the following can lead to endless loop:
loop() :-
retract(fct(X)),
... % creating Y from X
asserta(fct(Y)),
fail.
这样会导致死循环!!