xsb“没有过程usermod”,当谓词已经定义

时间:2016-05-18 08:03:19

标签: prolog xsb

所以在我的文件中我有

:- use_module(standard, datime/1).

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

直接在命令行中运行

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

但是加载文件本身并运行该函数会产生错误

| ?- [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

知道为什么会这样,以及如何解决这个问题?对于文件中的其他谓词也会发生这种情况。

1 个答案:

答案 0 :(得分:1)

您的代码有3个问题:

  1. 您对today/3的声明缺少结束)
  2. today/3未导出
  3. use_module/2需要一个符号列表作为第二个参数,或者使用import sym from mod
  4. 如果您将utils.P文件定义为以下

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

    您可以通过以下任一方式使用它:

    直接导入谓词:

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

    使用:

    使用限定名称
    | ?- utils:today(Y,M,D).
    
    Y = 2016
    M = 5
    D = 18
    

    直接加载模块

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