Error using library clpfd. Module clpfd seems to be unusable until manually loaded

Using SWI-Prolog (threaded, 64 bits, version 8.3.25)

File: my_clpfd.pl

:- module(my_clpfd,
    [
    ]).

:- use_module(library(clpfd)).

Example run with error.

Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.25)

...

?- working_directory(_,'C:/Users/Eric/Documents/Projects/SWI-Prolog/XYZ').
true.

?- [my_clpfd].
true.

?- X in 1..2.
ERROR: Syntax error: Operator expected
ERROR: X
ERROR: ** here **
ERROR:  in 1..2 . 

?- current_module(clpfd).
true.

?- use_module(library(clpfd)).
true.

?- X in 1..2.
X in 1..2.

?- current_module(clpfd).
true.

I was expecting the use of the directive :- use_module(library(clpfd)). in my_clpfd to load the library clpfd and work. Using current_module(clpfd) to check shows that the module was loaded but when using X in 1..2. the error is generated.

Out of curiosity I manually loaded the module in the top level, use_module(library(clpfd)). and then tried X in 1..2. again and it worked.

I am at a lost to why and if I did something wrong. :thinking:

Also checked what happens if I don’t load my module my_clpfd which responded as expected.

Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.25)

...

?- current_module(clpfd).
false.

?- X in 1..2.
ERROR: Syntax error: Operator expected
ERROR: X
ERROR: ** here **
ERROR:  in 1..2 . 
?- use_module(library(clpfd)).
true.

?- current_module(clpfd).
true.

?- X in 1..2.
X in 1..2.

EDIT

I uninstalled SWI-Prolog and checked that the directory C:\Program Files\swipl was removed and reinstalled SWI-Prolog and still same problem.

I cannot see why you call that behaviour problematic.
You could reexport/1 (or parts of - with reexport/2) the interface of library(clpfd) from module(my_clpfd).

OK.

So I should not be thinking that because I loaded the libary(clpfd) from my module my_clpfd the predicates in library(clpfd) are accessible at the top level, user.

Thanks.


EDIT

For others also curious about understanding this.

Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.25)

...

?- current_predicate(Module:in/N_).
false.

?- X in 1..2.
ERROR: Syntax error: Operator expected
ERROR: X
ERROR: ** here **
ERROR:  in 1..2 . 
?- working_directory(_,'C:/Users/Eric/Documents/Projects/SWI-Prolog/XYZ').
true.

?- [my_clpfd].
true.

?- current_predicate(Module:in/N_).
Module = clpfd,
N_ = 2 ;
Module = my_clpfd,
N_ = 2 ;
false.

?- X in 1..2.
ERROR: Syntax error: Operator expected
ERROR: X
ERROR: ** here **
ERROR:  in 1..2 . 
?- use_module(library(clpfd)).
true.

?- current_predicate(Module:in/N_).
Module = user,
N_ = 2 ;
Module = clpfd,
N_ = 2 ;
Module = my_clpfd,
N_ = 2 ;
false.

?- X in 1..2.
X in 1..2.

Also see:
Properties of modules and predicates
Interacting with modules from the top level