prologxsb

xsb "No procedure usermod" when predicate is already defined


So in my file I have

:- use_module(standard, datime/1).

today(Y, M, D) :-
    datime(datime(Y, M, D, _, _, _).

Running this directly in the command line gives

XSB Version 3.6. (Gazpatcho) of April 22, 2015
[x86-pc-windows; mode: optimal; engine: slg-wam; scheduling: local]
[Build date: 2015-04-22]

| ?- use_module(standard, datime/1).

yes
| ?- datime(datime(Y, M, D, _, _, _)).

Y = 2016
M = 5
D = 17

yes

But loading the file itself and running the function gives an error

| ?- [utils].
[Compiling .\utils]
[utils compiled, cpu time used: 0.0780 seconds]
[utils loaded]

yes
| ?- today(Y, M, D).
++Error[XSB/Runtime/P]: [Existence (No procedure usermod : today / 3 exists)] []
Forward Continuation...
... machine:xsb_backtrace/1  From C:\Program Files (x86)\XSB\syslib\machine.xwam
... loader:load_pred1/1  From C:\Program Files (x86)\XSB\syslib\loader.xwam
... loader:load_pred0/1  From C:\Program Files (x86)\XSB\syslib\loader.xwam
... loader:load_pred/1  From C:\Program Files (x86)\XSB\syslib\loader.xwam
... x_interp:_$call/1  From C:\Program Files (x86)\XSB\syslib\x_interp.xwam
... x_interp:call_query/1  From C:\Program Files (x86)\XSB\syslib\x_interp.xwam
... standard:call/1  From C:\Program Files (x86)\XSB\syslib\standard.xwam
... standard:catch/3  From C:\Program Files (x86)\XSB\syslib\standard.xwam
... x_interp:interpreter/0  From C:\Program Files (x86)\XSB\syslib\x_interp.xwam
... loader:ll_code_call/3  From C:\Program Files (x86)\XSB\syslib\loader.xwam
... standard:call/1  From C:\Program Files (x86)\XSB\syslib\standard.xwam
... standard:catch/3  From C:\Program Files (x86)\XSB\syslib\standard.xwam

Any idea why this is the case and how to fix this? This happens for other predicates in the file as well.


Solution

  • There are 3 problems with your code:

    1. Your declaration of today/3 is missing a closing ),
    2. today/3 isn't exported
    3. use_module/2 expects a list of symbols as second argument, alternatively use import sym from mod.

    If you define your utils.P file as following

    :- import datime/1 from standard.
    :- export today/3.
    today(Y, M, D) :- datime(datime(Y, M, D, _, _, _)).
    

    you can use it in either of the following ways:

    Import the predicate directly:

    | ?- import today/3 from utils.
    
    yes
    | ?- today(Y,M,D).
    
    Y = 2016
    M = 5
    D = 18
    

    use a qualified name using :

    | ?- utils:today(Y,M,D).
    
    Y = 2016
    M = 5
    D = 18
    

    loading the module directly

    | ?- [utils].
    [utils loaded]
    
    | ?- today(Y,M,D).
    
    Y = 2016
    M = 5
    D = 18