# Stripped out modules, unit test no longer work

**URL:** <https://swi-prolog.discourse.group/t/stripped-out-modules-unit-test-no-longer-work/3814>\
**Category:** Help!\
**Created:** [April 10, 2021, 9:17am UTC](https://swi-prolog.discourse.group/t/stripped-out-modules-unit-test-no-longer-work/3814 "2021-04-10T09:17:33Z")\
**Posts on this page:** 1\
**Showing post:** 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 10, 2021, 12:03pm UTC](https://swi-prolog.discourse.group/t/stripped-out-modules-unit-test-no-longer-work/3814/2 "2021-04-10T12:03:32Z")

</div>

> [@emacstheviking](#):
>
> traditional (no modules)

IMHO I do not consider `no modules` as traditional.

About the only time I use code without modules is to do some quick predicates in the top level or to quickly answer a posted question with some code. My default way of writing any Prolog code I intend to keep around is to use modules. As a matter of fact I rely on modules so much that I typically cut and paste code like this when opening a new \*.pl file.

```prolog
:- module(module_name,
    [
        prediate_1/3,
        prediate_2/5
    ]).

% -----------------------------------------------------------------------------

% DELETE THIS SECTION BEFORE POSTING

:- if(current_prolog_flag(windows,true)).
:- working_directory(_,'C:/Users/Me/Documents/Projects/SWI-Prolog/Project').
:- elif(current_prolog_flag(unix,true)).
:- working_directory(_,'/mnt/c/Users/Me/Documents/Projects/SWI-Prolog/Project').
:- endif.

% [module_name].

% ----------------------------------------------------------------------------

:- multifile
    other_module:other_prediacate/3.

% ----------------------------------------------------------------------------

```

and like this for the corresponding \*.plt file

```prolog
% Note: No module declaration for plt files.

% -----------------------------------------------------------------------------

% DELETE THIS SECTION BEFORE POSTING

:- if(current_prolog_flag(windows,true)).
:- working_directory(_,'C:/Users/Me/Documents/Projects/SWI-Prolog/Project').
:- elif(current_prolog_flag(unix,true)).
:- working_directory(_,'/mnt/c/Users/Me/Documents/Projects/SWI-Prolog/Project').
:- endif.

% [module_name].

% [trace] ?- run_tests(my_module:my_test).

% ----------------------------------------------------------------------------

:- begin_tests(my_module).

:- use_module(other_module_1).
:- use_module(other_module_2).

% count tests

% Number of unique something.
test(count_of_something) :-
    % gtrace,
    number_of_something(10).

:- end_tests(my_module).

```

I did a lot of changes in the above code so as not to reveal real names and such so don’t expect the code to compile if copied.

* * *

> [@emacstheviking](#):
>
> Maybe I am too dumb after all

Don’t even think that!!! 😀

I get stuck on problems so often that when a day goes by without a problem I wonder if I did anything productive.

As I have noted many times here, I spent many many months grappling with DCGs before I finally felt comfortable with them. Still don’t have them down enough that I could write a Wiki I consider complete but do know them enough that I don’t hesitate to use them for any problem needing Prolog list, generators or parsers.

* * *

One thing I have learned about using Prolog with modules is that if I think in hierarchies of modules like object oriented languages it leads to nothing but trouble. The Prolog module system is very flat. What helped me understand this was using [Cystoscape](https://cytoscape.org/) to graph the module dependencies: See: [Wiki Discussion: Generating Cytoscape.js graphs with SWI-Prolog - #4 by EricGT](https://swi-prolog.discourse.group/t/wiki-discussion-generating-cytoscape-js-graphs-with-swi-prolog/2816/4).

The posted graph is not what gave me the [ah-ha](https://www.merriam-webster.com/dictionary/ah-ha) moment but after hand adjusting the vertexes it lead to the ah-ha moment.

---

_[View the full topic](https://swi-prolog.discourse.group/t/stripped-out-modules-unit-test-no-longer-work/3814)._
