?- assertz(:- module(foo1, [f/1])).
true.
?- foo1:assertz(f(1)).
true.
?- foo1:f(1).
true.
?- foo2:f(1).
Correct to: "foo1:f(1)"? no
ERROR: Undefined procedure: foo2:f/1
ERROR: In:
ERROR: [8] foo2:f(1)
ERROR: [7] <user>
Makes sense to me. But then (from scratch)....
?- assertz(:- module(foo1, [f/1])).
true.
?- assertz(f(1)).
true.
?- foo1:f(1).
true.
?- foo2:f(1).
true. # Wait, what? foo2 doesn't appear in my program. Should fail?
?- frobnoz:f(1).
true. # Also odd!
But then...
?- foo2:assertz(f(1)).
true.
?- foo2:f(1).
true.
?- frobnoz:f(1).
ERROR: Undefined procedure: frobnoz:f/1
How does f get added to foo2 when I don't mention foo2.
Why does frobnoz:f succeed in the second example, but fail in the third?
What are modules? I thought they were namespaces, but am now confused.
1st question:
From SWI-Prolog Manual - Module autoload section:
You can go deeper but, basically, when the module is not explicitly defined, prolog search for it and silently loads it. It's the default behavior. You can change it with autoload flag.
2nd question:
Probably this
frobnoz:fcan be found as a dependency fromfoo1module, which you are not referencing in the third example.3rd question:
As SWI-Prolog Reference Manual reads: