Interfacing with another program -- how do i read in program data (not just strings/codes)

I have the server/client communication working as at the bottom of this page

This gets data from the client as “codes” and formats it to print it out as a string:
(read_line_to_codes(In, Command),
format(Out, ‘Please to meet you: ~s~n’, [Command])

But I want to parse it into Prolog, so that either it gets a fact(s) from the client, and adds it to the set of known facts, or it gets a query from the client, and returns a result.

So (first) I need to know how to parse and evaluate in a fact or query, rather than just ending up with a string or codes. Any help is appreciated!

You probably want to look at read_term and the various related predicates in that section, which you can then just call/1 or assertz/1.

However, if you want a more robust client-server way of executing Prolog code, Pengines may be more what you’re looking for.

edit: also, if you want to just have a remote prolog listener, there’s the built-in prolog_server.

Thanks, that was very helpful! I’m using prolog_server now.

The results come out as in the standard user interface – one unified variable per line. Is there any way of changing this printer globally, or wrapping the commands so that the result comes out in a different format? E.g. a JSON tuple would be nice… I’ve looked through the JSON stuff in the documentation, but I haven’t found a way to do this.