Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between abolish/1 and retractall/1?

From reading the manual, I can't seem to find the difference between the two.

The manual says:

It is advised to use retractall/1 for erasing all clauses of a dynamic predicate.

So I chose to use retractall/1 in my program; however, I wonder what the difference is.

like image 482
Kevin Van Ryckegem Avatar asked Dec 27 '15 21:12

Kevin Van Ryckegem


3 Answers

In analogy to SQL:

retractall(table_name(_,_,_)) could be delete from table_name, while abolish(table_name/3) would play as drop table_name

like image 57
CapelliC Avatar answered Nov 03 '22 10:11

CapelliC


The retractall/1 standard built-in predicate can be used to remove all clauses for a dynamic predicate but the predicate will still be known by the runtime. The abolish/1 standard built-in predicate, in the other hand, not only removes all predicate clauses but also makes the predicate unknown to the runtime. If you try to call a dynamic predicate after removing all its clauses using retractall/1, the call simply fails. But if you abolish a dynamic predicate, calling it after will result in a predicate existence error.

like image 38
Paulo Moura Avatar answered Nov 03 '22 11:11

Paulo Moura


Before I read your question and @PauloMoura's fine answer, I didn't know the answer either.

With this answer I don't want to copy Paulo's answer. Instead, I suggest you consider reading/searching alternative Prolog-related sources:

  • The ISO directives, control constructs and builtins—iso-prolog on SO

  • 4.12.5 Removing Clauses from the Database—sicstus-prolog manual

  • 8.7 Dynamic clause management—gnu-prolog manual

  • Chapter 9 Dynamic Clauses and Global Variables—bprolog manual

  • 6.14 Asserting, Retracting, and Other Database Modifications—xsb manual

  • 6.10.1 Modification of the Data Base—part of the yap manual

Note that the above may or may not directly fit the Prolog system you use.

Still, having multiple sources is a good thing: It can keep you from getting stuck!

like image 28
repeat Avatar answered Nov 03 '22 11:11

repeat