George
George

Reputation: 337

SWI Prolog query

:- dynamic plop/2
add(Var):-
    retract(plop(Var,X))->
    (X = X+1, assert(plop(Var,X)));
    (assert(plop(Var,1))).

So if i call add(y). it will create plop(y,1) but when i call add(y). again why wont it add one to the so it will be plop(y,2)

Upvotes: 2

Views: 184

Answers (1)

liori
liori

Reputation: 42377

Because there is no X that would fulfill this relationship: X = X+1, and the rule fails. Try Y is X+1, assert(plop(Var,Y)) there instead.

Upvotes: 6

Related Questions