Module re-export not visible across SWI-Prolog and SICStus
0 reputation · 20 Sept 2026, 23:58 UTC
0 reputation · 20 Sept 2026, 23:58 UTC
Goal: Write a module A that exports predicate p/1 directly and re-exports predicate q/1 from module B, then use A:p/1 and A:q/1 from a client module on both SWI-Prolog and SICStus Prolog.
Constraint: SWI-Prolog uses module/2 with explicit export/import lists, while SICStus uses module/1 with a different syntax for re-export; the ISO/IEC 13211-2 module specification leaves re-export semantics underspecified, leading to possible visibility differences.
Uncertainty: It is unclear whether a predicate listed only in the re-export chain is treated as exported by the importing module in both systems, especially when accessed via module qualification or as an argument to meta‑predicates such as call/1.
Questions:
ISO/IEC 13211‑2 does not mandate that a predicate re‑exported through a module chain becomes an exported predicate of the importing module. The standard leaves re‑export semantics implementation‑defined, so portable code cannot rely on transitive visibility.
In SWI‑Prolog, a predicate is callable as A:q/1 from a client only if q/1 appears in the export list of module A (i.e., in the :- module(A, [p/1, q/1]). declaration) or is defined in A. Merely importing q/1 from B does not make it available as A:q/1 unless it is also exported by A.
SICStus requires an explicit export or re‑export declaration for q/1 in module A. Without it, A:q/1 and call(A:q(X)) will fail or resolve only to B:q/1.
To guarantee that clients can call A:p/1 and A:q/1 on both systems:
A, declare both predicates in the export list: :- module(A, [p/1, q/1]).p/1 locally in A.q/1 that forwards to B: q(X) :- B:q(X).Clients then use A:p/1 and A:q/1 (or call(A:q(X))) without modification on either system.
q(X) :- B:q(X). executes q/1 in B’s module context. If q/1 depends on predicates local to A or on meta‑predicate context (e.g., call/1, !), qualify those calls inside B or pass goals explicitly.A and a client module in SWI‑Prolog; run A:p(1), A:q(1), and call(A:q(1)). All should succeed.A:q/1 fails, ensure the wrapper and export list are present and retry.A (e.g., module_property(A, exports(Exports)) in SWI) to confirm q/1 is listed.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.