# I don't understand how unload\_file/1 works with modules

**URL:** https://swi-prolog.discourse.group/t/i-dont-understand-how-unload-file-1-works-with-modules/3728
**Category:** Help!
**Created:** [March 17, 2021, 2:24pm UTC](https://swi-prolog.discourse.group/t/i-dont-understand-how-unload-file-1-works-with-modules/3728 "2021-03-17T14:24:16Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![stassa.p](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/stassa.p/32/712_2.png) [@stassa.p](https://swi-prolog.discourse.group/u/stassa.p)
#### Post date: [March 17, 2021, 2:24pm UTC](https://swi-prolog.discourse.group/t/i-dont-understand-how-unload-file-1-works-with-modules/3728/1 "2021-03-17T14:24:16Z")

</div>

What I don’t understand is what happens when a module file is unloaded and then reloaded. I thought I should be able to re-load a previously unloaded file without starting a new session, but that doesn’t seem to be the case. I show an example of this below:

Test module:

```prolog
:-module(test_module, [def/0]).
def.

```

Some queries:

```prolog
?- def.
true.

?- unload_file(test_module).
true.

?- def.
ERROR: Unknown procedure: def/0 (DWIM could not correct goal)

```

That’s as expected. But now what happens if I try to reload the previously unloaded module?

```prolog
?- use_module(test_module).
true.

?- def.
ERROR: Unknown procedure: def/0 (DWIM could not correct goal)
?- listing(def).
ERROR: procedure `def' does not exist (DWIM could not correct goal)
^ Exception: (13) setup_call_catcher_cleanup(system:true, prolog_listing:listing_(user:def, []), _8646, prolog_listing:close_sources) ? abort
% Execution Aborted
?- test_module:def.
ERROR: Unknown procedure: test_module:def/0 (DWIM could not correct goal)

```

There was no error raised by use\_module/1, yet the definition of def/0 in test\_module is nowhere to be found in the program database. Is that the expected behaviour? Is there no way to reload the definitions of predicates in a previously unloaded module?

Why would I ever want to unload and then reload a module? To ensure that the definitions of predicates in that module are the ones actually defined in the module file and not added to the program database by some other process (i.e. by manipulating the dynamic database directly).

More generally, there are situations where I would like to be able to “refresh” my program database to the state it was in when a set of source files were initially loaded without having to start a new session. Is that possible?

Edit: Forgot to say. I’m using Swi on Windows with this version :

```prolog
Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.20)

```
