gnu-prolog - ошибка предиката инициализации

При компиляции и запуске кода ниже (pl_check_input.pl) я получаю "user directive failed" в строке ":-initialization..."

:- 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.


person paul tarvydas    schedule 31.10.2017    source источник
comment
(динамические/инициализация/включение находятся в отдельных строках)   -  person paul tarvydas    schedule 31.10.2017
comment
MCVE, пожалуйста.   -  person false    schedule 01.11.2017


Ответы (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
person paul tarvydas    schedule 01.11.2017