Make/0 and delete_file/1

I’m using: SWI-Prolog version 8.1.12

I load a program “” containing a directive “:- ensure_loaded(a).” where contains a single clause, say “a(a).”.
When I modify in my editor (e.g. to “a(b).”) and call make/0 in my top-level, my prolog program gets updated as expected.
If I then delete file (e.g. delete_file(‘’).) and then call make/0, my program does not change, and no error is thrown.
Could you please help to clarify, what should be the expected behaviour of make/0, when one of the loaded files goes out of existence?


Make/0 reloads edited files. It isn’t a full consistency mechanism between the file system and the Prolog database. In many places that is also impossible as removing things that used to be there and in particular side effects thereof are hard to track and undo.

Possibly it should once be described what you can and cannot expect from make/0. Deleting files doesn’t seem to be a very common task during program development to me. You could make the file empty, run make/0 and delete it :slight_smile: There is also unload_file/1, but that too has its limitations.

1 Like

Somebody could try to bring module garbage collection to SWI-Prolog. Garbage collecting Prolog modules is feasible. This is a variant of Erlang hot swap. This works already, just take this example:

Module a:

:- use_module(b).
:- use_module(c).

You get the following dependency graph:

                     /----->  b   
           user --> a 
                     \------> c

When you load the module “a” you get 3 loads:


?- use_module(a).
% 3 consults and 0 unloads in 6 ms.

Now make a change in the module dependency:

Modified Module a:

:- use_module(b).
% :- use_module(c).

You get the following modified dependency graph:

                     /----->  b   
           user --> a 

Now invoke make/0, the module “c” will be garbage collected and thus unloaded:


?- make.
% 1 consults and 1 unloads in 3 ms. 

Here is a screenshot:


Disclaimer: Still experimental.