I am trying to implement a simple Prolog server with a JSON interface using this gist from @jan
from this thread. I’m running into a problem when using consult/1 to load files. I think it stems from the fact that the server is acting like one big, long running query that never halts. Here’s a simplification of the important code from the server:
% Pass in the TCP/IP Stream that commands get sent upon serve_loop(ReadStream) :- read_term(ReadStream, Command, ), call(Command), serve_loop(ReadStream).
Here’s the problem: If I call the server once to consult a file and then once to call a predicate from inside that file, it fails with “ERROR: Unknown procedure”. I suspect it could be related to the behavior below. It appears as though running a single query that includes a consult/1 along with references to terms inside it doesn’t work:
% Test.pl foo(X) :- writeln(X).
?- consult("/.../Test.pl"), foo(a). ERROR: Unknown procedure: foo/1 (DWIM could not correct goal) ?- consult("/.../Test.pl"). true. ?- foo(a). a true.
Any clues as to what is going on and how to fix it?