Swi Prolog, unloading source files

file, prolog, swi-prolog

Solution

You can do it 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` abolishes all predicates defined by the input Source file name. Be warned that it needs to be an absolute path.

`unload_last_source/0` will retrieve the last consulted file name and unload it.

Problem

Is there a built-in predicate or a easy way to remove from the knowledge database of prolog a source files that has already been consulted? I've gone through the reference manual and didn't find any thing that could do that.

Original source