Stripped out modules, unit test no longer work

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.

:- 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

% 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.


Don’t even think that!!! :grinning:

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 to graph the module dependencies: See: Wiki Discussion: Generating Cytoscape.js graphs with SWI-Prolog - #4 by EricGT.

The posted graph is not what gave me the ah-ha moment but after hand adjusting the vertexes it lead to the ah-ha moment.