Module clashing with apply:include/3

Hi, I’ve hit a problem I can’t find my way around…in my “language” I have a predicate for each reserved word, so that I can use call/1, here’s the handling of a built-in function:

render(Options, Term, CodeOut) :-
    debug(coder, 'C:render: ~w',[Term]),
    (   functor(Term, F, _),
        reserved_word(F)
    ->  call(F, Options, Term, CodeOut)
    ;   fncall(Options, Term, CodeOut)
    ),
    !.

The problem is, I have a reserved word include and it’s clashing with apply:include/3 …I am using maplist elsewhere and I assumed that was auto-loading apply libraru, I have tried and failed with

:- use_module(library(apply), [maplist/3]).

attempting to only include maplist and I also tried this to not pull in the include

:- use_module(library(apply), except([include/3]).

but neither avoids this:
ERROR: No permission to redefine imported_procedure apply:include/3’`

Here is the code that it won’t chew on:

include(_Opts, _Term, "INCOLUDE TODO").

One way would be to prefix all the handlers with something then use format to create the final name to call/1 but that feels inefficient and ugly.

TIA.
Sean.

I have worked around by returning a functor called “include_file” to alleviate the class. Not ideal as it means I don’t yet understand the nature of the problem enough to fix it the “right way”.

I thought it was something with autoloading and was going to suggest turning autoloading off, but I just tried & can’t reproduce this. e.g. a module like the below loads fine & doesn’t seem to give an error:

:- module(foo, [include/3]).

:- use_module(library(apply), [maplist/3]).

include(A, B, C) :-
    maplist([Y, Z]>>(Z is Y + 1), [1,2,3], X),
    format("INCLUDE ~w ~w ~w, ~w", [A, B, C, X]).

what if you pull in all of the apply library…does it reproduce?

If I include all of apply, I get a warning Local definition of foo:include/3 overrides weak import from apply.

That is all completely normal. You can redefine any non-ISO predicate locally. If you also import the library that contains it you get the overrides weak import message. I guess there is something else in the file that prevents this from working. For example, you do get this issue if loading the file somehow calls include/3 before the local definition is present. In that case the autoloader kicks in and gets the predicate from the library. That should prevent subsequent local definition. E.g., this raises an error:

:- include(integer, [1,a], _).

include(a,b,c).
1 Like

Well, I haven’t been able to solve it yet sadly and my workaround …didn’t! :unicorn: