Here is something unexpected about Modules:
Suppose you have two modules:
In file1.pl
:
:-module('com.example.megacorp', [make_money/2]).
make_money("Make more money!", "Yes, sir").
In file2.pl
:
:-module('com.example.megacorp.hq', [make_money/2]).
make_money("Make more money!", "Yes, sir").
Note that the module names differ, but the exported predicates have the same descriptor (using correct ISO terminology, the exported procedures have the same predicate indicator, but we know what we mean)
Then, in the REPL:
?- [file1].
true.
?- [file2].
ERROR: import/1: No permission to import 'com.example.megacorp.hq':make_money/2 into user (already imported from 'com.example.megacorp')
true.
Okay. But now:
In file1.pl
, unchanged:
:-module('com.example.megacorp', [make_money/2]).
make_money("Make more money!", "Yes, sir").
In file2.pl
, I leave the list of publicly visible predicates as it was (erroneously) and just change the name of the defined procedure:
:-module('com.example.megacorp.hq', [make_money/2]).
make_money_2("Make more money!", "Yes, sir").
Unexpectedly, both files can be loaded.
?- [file1].
true.
?- [file2].
true.
I didn’t expect that. Why is this possible?