Search code examples
prologprolog-assert

How to generate an assert that forces a false?


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!


Solution

  • just add parenthesis:

    ?- asserta((some_fact:- fail, !)).
    true.