在编译和运行下面的代码(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管道脚本中,并删除top-level/0附带的各种标语行。
发布于 2017-11-02 00:26:22
“不要紧”,它被证明是一个缺失的规则,生成了一个非常误导性的错误消息。要复制该错误,请创建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 failedhttps://stackoverflow.com/questions/47040222
复制相似问题