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

From reading the manual, I cannot find the difference between the two.

The manual says:

It is recommended that you use retractall / 1 to erase all dynamic predicate sentences.

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

+5
source share
3 answers

The standard built-in predicate retractall/1 can be used to remove all sentences for a dynamic predicate, but the predicate will still be known at runtime. On the other hand, the standard built-in predicate abolish/1 not only removes all predicate sentences, but also makes the predicate unknown to the runtime. If you try to call a dynamic predicate after deleting all of your sentences with retractall/1 , the call will simply fail. But if you cancel the dynamic predicate by calling it after this will lead to the error of the existence of the predicate.

+6
source

Similar to SQL:

retractall(table_name(_,_,_)) can be delete from table_name , while abolish(table_name/3) will play like drop table_name

+4
source

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

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

Please note that the above may or may not directly correspond to the Prolog that you use .

However, having multiple sources is good: it can prevent you from getting stuck!

+2
source

Source: https://habr.com/ru/post/1239312/


All Articles