【问题标题】:gnu-prolog - initialization predicate failinggnu-prolog - 初始化谓词失败
【发布时间】:2017-10-31 16:32:15
【问题描述】:

在编译和运行下面的代码 (pl_check_input.pl) 时,我在“:-initialization...”行得到“user directive failed”

:- dynamic(doit/0).
:- initialization(doit).
:- include(head).

doit :-
    readFB(user_input),
    writeFB,
    halt.

:- include(tail).

$ gplc --no-del-temp --no-top-level pl_check_input.pl
$ ./pl_check_input <fb1 >fb2
warning: /home/tarvydas/Dropbox/Projects/vsh/pl-vsh/pl_check_input.pl:2: user directive failed

如果我删除违规行

:- dynamic(doit/0).
:- include(head).

doit :-
    readFB(user_input),
    writeFB,
halt.

:- include(tail).

$ gplc --no-del-temp --no-top-level pl_check_input.pl
$ ./pl_check_input <fb1 >fb2
Warning: no initial goal executed
   use a directive :- initialization(Goal)
   or remove the link option --no-top-level (or --min-bips or --min-size)

非常欢迎任何见解。

最终,我从REPL 运行了这段代码,但我想把它放在一个 linux 管道脚本中,并删除顶级/0 附带的各种横幅行。

【问题讨论】:

  • (动态/初始化/包含在不同的行)
  • MCVE,请。

标签: command-line gnu-prolog


【解决方案1】:

“没关系”,事实证明这是一个缺失的规则,产生了一个非常误导性的错误消息。要复制错误,请创建 junk.pl:

:- initialization(main).
:- include(head).

main :-
    readFB(user_input),
    writeFB,
    halt.

:- include(tail).

并创建文件head.pl:

:- dynamic(component/1) .
:- dynamic(edge/1) .

创建文件tail.pl(注释掉的第一行是缺少的规则)

% writeterm(Term) :- current_output(Out), write_term(Out, Term, []), write(Out, '.'), nl.


writeFB :-
    forall(component(X), writeterm(component(X))),
    forall(edge(X), writeterm(edge(X))).

readFB(Str) :-
    read_term(Str,T0,[]),
    element(T0,Str).

element(end_of_file, _) :- !.
element(component(X), Str) :- !,
               asserta(component(X)),
               readFB(Str).
element(edge(X), Str) :- !,
               asserta(edge(X)),
               readFB(Str).

创建文件 fb1a:

component('pl_vsh') .
edge(e0) .

然后运行编译并执行命令:

$ gplc junk.pl --no-top-level 
$ ./junk <fb1a >fb2

导致错误消息:

warning: /home/xxx/xxx/xxx/xxx/xxx/junk.pl:1: user directive failed

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多