0

在编译和运行下面的代码 ( pl_check_input.pl) 时,我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 附带的各种横幅行。

4

1 回答 1

0

“没关系”,事实证明这是一个缺失的规则,产生了一个非常误导性的错误消息。要复制错误,请创建 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
于 2017-11-01T16:26:22.177 回答