0

In compiling and running the code below (pl_check_input.pl), I get "user directive failed" on the ":- initialization..." line

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

If I remove the offending line

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

Any insights would be very welcome.

Ultimately, I have this code running from the REPL, but I want to put it in a linux pipeline script and remove the various banner lines that come with top-level/0.

false
  • 10,264
  • 13
  • 101
  • 209

1 Answers1

0

"never mind", it turned out to be a missing rule that generated a very misleading error message. To duplicate the error, create junk.pl:

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

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

:- include(tail).

and create file head.pl:

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

create file tail.pl (the first commented out line is the missing rule)

% 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).

create file fb1a:

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

then run a compile and execute the command:

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

which results in the error message:

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