scryer-prolog icon indicating copy to clipboard operation
scryer-prolog copied to clipboard

Term expansion is unexpectedly not confined to its module

Open triska opened this issue 1 year ago • 1 comments

For instance, with m.pl comprising:

:- module(m, []).

term_expansion(a, b) :- write(hello).

and p.pl comprising:

:- use_module(m).

a.

I get:

$ scryer-prolog p.pl
hello

The term expansion defined in m.pl is expected to be confined to that module, and should not affect the fact a. which is defined in p.pl.

triska avatar Oct 05 '24 23:10 triska

This seems problematic but not entirely unexpected.

In both SWI and SICStus, term_expansion is a hook predicate in the user module, blissfully unaware of the module you're declaring it in.

The weird parts to me (and unlike in SICStus) are: (1) it is implicitly asserted to the user module, instead of needing to be explicitly qualified (e.g. user:term_expansion(a,b) :- write(hello)). (2) it is implicitly multifile, instead of needing to be declared such.

I don't know if it would uncomfortably different from other Prologs, but it seems more uniform to have such expansion rules registered with a directive (similar to how you hook into initialization with an :- initialization(G) declaration), NOT by defining a "magic" functor.

rotu avatar May 14 '25 00:05 rotu