Search code examples
prologpredicate

How to completely remove a predicate in Prolog?


I have the predicate color/2 with the following facts:

color(omlette, yellow).
color(tomato, red).
color(cucumber, green).
...

Now I want to completely remove it from the system, i.e. I want current_predicate(color/2) to fail. However, even if I retractall(color(_, _)), and indeed all facts relating to color are removed, current_predicate(color/2) would still succeed.

How can I make it fail?


Solution

  • Use abolish/1 to completely remove all the clauses of a procedure and its attributes:

    abolish(color/2).
    

    Depending on your prolog processor you may have to indicate that the procedure is dynamic, in your example with

    :-dynamic(color/2).