Swi Prolog, uploading source files

Is there a built-in predicate or an easy way to remove the prolog of source files that have already been consulted from the knowledge database? I read the reference manual and did not find anything that could do this.

+4
source share
3 answers

You can do this with these procedures, which use source_file/1 and source_file/2 :

 unload_last_source:- findall(Source, source_file(Source), LSource), reverse(LSource, [Source|_]), unload_source(Source). unload_source(Source):- ground(Source), source_file(Pred, Source), functor(Pred, Functor, Arity), abolish(Functor/Arity), fail. unload_source(_). 

unload_source/1 cancels all predicates defined by the name of the source source. Be warned that this should be an absolute path.

unload_last_source/0 will extract the last file name and unload it.

+4
source

Once the file is consulted, it will become "inappropriate" for Prolog. Therefore, I think that in general the answer should be no . But SWI-Prolog has a rich set of built-in functions that allows you to control your programs. For instance,

 ?- [stackoverflow]. ?- predicate_property(P, file('/home/carlo/prolog/stackoverflow.pl')). P = yield(_G297, _G298) ; P = now _G297 ; P = x(_G297) ; ... ?- abolish(yield/2). true. ?- predicate_property(P, file('/home/carlo/prolog/stackoverflow.pl')). P = now _G297 ; P = x(_G297) ; ... 

Please note that undoing is not required for the file name to work; you can remove predicates loaded from other source files.

clause , clause_property and erase should give more control, but I get an error message that I don't understand (it's undocumented) when I try to use erase:

 ?- clause(strip_spaces(_G297, _G298),X,Y),erase(Y). ERROR: erase/1: No permission to clause erase `<clause>(0x29acc30)' 
+1
source

if you know the name of the predicate, for example fact / 2, you can use:

 retractall(fact(_,_)). 
0
source

All Articles