# Unexpected behaviour in user module

**URL:** https://swi-prolog.discourse.group/t/unexpected-behaviour-in-user-module/502
**Category:** Help!
**Created:** [April 7, 2019, 12:32pm UTC](https://swi-prolog.discourse.group/t/unexpected-behaviour-in-user-module/502 "2019-04-07T12:32:30Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![fsaenzperez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/fsaenzperez/32/50_2.png) [@fsaenzperez](https://swi-prolog.discourse.group/u/fsaenzperez)
#### Post date: [April 7, 2019, 12:32pm UTC](https://swi-prolog.discourse.group/t/unexpected-behaviour-in-user-module/502/1 "2019-04-07T12:32:30Z")

</div>

With no module already defined, is the following an expected behaviour?

```prolog
?- assert(p).
true.

?- foo:p.
true.

```

Since `foo` is not defined, I’d expect an error message about either a non-existent predicate or module. (Running in SWI-Prolog 8.0.2)

---

<div class="post-metadata">

### Author: ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)
#### Post date: [April 7, 2019, 12:51pm UTC](https://swi-prolog.discourse.group/t/unexpected-behaviour-in-user-module/502/2 "2019-04-07T12:51:06Z")

</div>

From a fresh startup of swipl. (I am using SWI-Prolog AMD64, Multi-threaded, version 8.0.0)

```prolog
?- current_module(X).
X = prolog_history ;
X = pce_expansion ;
X = prolog_clause ;
X = prolog_stack ;
X = broadcast ;
X = predicate_options ;
X = pce_swi_hooks ;
X = read_util ;
X = arithmetic ;
X = prolog_debug ;
X = pairs ;
X = win_menu ;
X = qsave ;
X = link_xpce ;
X = error ;
X = ansi_term ;
X = prolog_listing ;
X = occurs ;
X = prolog_source ;
X = settings ;
X = user ;
X = listing ;
X = prolog_operator ;
X = shlib ;
X = system ;
X = lists ;
X = prolog ;
X = swi_option ;
X = apply ;
X = sandbox ;
X = base32 ;
false.

```

Notice that in the above list `foo` is not present.

```prolog
?- listing(p).
ERROR: procedure `p' does not exist (DWIM could not correct goal)
^ Call: (13) call(prolog_listing:close_sources) ? creep
^ Exit: (13) call(prolog_listing:close_sources) ? creep

```

```prolog
?- assert(p).
true.

?- listing(p).
:- dynamic p/0.

p.

true.

?- foo:p.
true.

?- current_module(foo).
true.

```

Notice that now `foo` is a valid module that was dynamically created.

See [Dynamic Modules](http://www.swi-prolog.org/pldoc/man?section=dynamic-modules)

However this will give an error:

```prolog
?- listing(foo:p).
ERROR: procedure `foo:p' does not exist (DWIM could not correct goal)
^ Call: (13) call(prolog_listing:close_sources) ? creep
^ Exit: (13) call(prolog_listing:close_sources) ? creep
?- 

```

Hopefully this gives you enough info to answer your question.

---

<div class="post-metadata">

### Author: ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)
#### Post date: [April 8, 2019, 6:46am UTC](https://swi-prolog.discourse.group/t/unexpected-behaviour-in-user-module/502/3 "2019-04-08T06:46:17Z")

</div>

I think you’ll find the answer in [Dynamic importing using import modules](http://www.swi-prolog.org/pldoc/man?section=importmodule)

---

<div class="post-metadata">

### Author: ![fsaenzperez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/fsaenzperez/32/50_2.png) [@fsaenzperez](https://swi-prolog.discourse.group/u/fsaenzperez)
#### Post date: [April 8, 2019, 9:56am UTC](https://swi-prolog.discourse.group/t/unexpected-behaviour-in-user-module/502/4 "2019-04-08T09:56:50Z")

</div>

Thanks! Both answers clarify what is going on with dynamic modules.

---

<div class="post-metadata">

### Author: ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)
#### Post date: [April 13, 2019, 11:46am UTC](https://swi-prolog.discourse.group/t/unexpected-behaviour-in-user-module/502/5 "2019-04-13T11:46:36Z")

</div>

For other finding this and looking for more information about SWI-Prolog modules.

See:  
[Using SWI-Prolog’s modules](http://chiselapp.com/user/ttmrichter/repository/gng/doc/trunk/output/tutorials/swiplmodtut.html)

[Modules in SWI Prolog](https://sewiki.iai.uni-bonn.de/_media/teaching/lectures/alp/2012/08_-_modules_and_objects.pdf)
