An infinite loop is generated when the inferential motor is activated to make the necessary inferences.
The rules and facts have been defined according to a specific syntax for the meta-interpreter I am using.
The rule is a quintuple in which the second field is the consequence of the rule while the third field are the conditions for activating a rule.
The cycle is caused by the updating of the id (I1) through the term nextID, which I used to make sure that each assert the id is incremented This is my knowledge base:
Rules:
rule(1,[gn(Name,Surname,I1),retract(nextID(I)),nextID(I1)],
and([person(Name,Surname),nextID(I),call_p(I1 is I+1),Name=='john']),1,1).
Facts:
fact(1,nextID(0),1).
fact(2,person(john,black),1).
How should I modify the rule in such a way that the infinite loop is not created?
From your description of the rule fields, I would expect a different formulation for that rule:
This would be equivalent to:
But it's hard to tell exactly without knowing the details of your rule engine.
Update
Given the formulation of facts, notably
fact(1,nextID(0),1), I wouldn't expect, however, that the embedded calls toretract/1andassertz/1would work. Isn'tcall_p/1the escape mechanism to call Prolog goals from rules?