Reputation: 5689
First of all thanks for your help.
On to my problem: Let's say I have:
some_fact:- true.
and I want to asserta a rule on top of it that looks like this:
some_fact:- fail, !.
This is because I want to transform the "some_fact:- true.
" to force a false without removing the rule (I don't want to use abolish(some_fact,0).
)
The problem is that I can't find the way to do it because I can't place the comma on the asserta/1. What I mean is that when I put:
asserta(some_fact:- fail, !).
the comma in between forces a call to asserta/2 instead of asserta/1 with the whole rule, and I cannot prevent that using quotes because it asserts a string.
Of course I can't just simply put asserta(some_fact:- fail).
because prolog will search for the next some_fact which returns true.
Any ideas? Thanks again!
Upvotes: 3
Views: 1506
Reputation: 91
To assert the fact:
asserta(zoo(zebra)).
When the fact is no longer true:
retract(zoo(zebra)).
More general:
asserting(Fact) :-
asserta(Fact).
retracting(Fact) :-
retract(Fact).
Example:
?- asserting(zoo(zebra)).
true.
?- zoo(zebra).
true.
?- retracting(zoo(zebra)).
true.
?- zoo(zebra).
false.
Upvotes: 1