Submitting Prolog Queries from GNU Emacs

GNU Emacs talks to Prolog by writing an Emacs-Lisp string in the form of a Prolog query (of any kind), terminated by a full-stop and prefixed by a special character code, to Prolog's standard input stream. When Prolog detects one of these prefixed queries in its term input stream, it executes the query as if it had been typed by the user at the top level. The query prefix character is ASCII 29.

As an example, define the function

     (defun to-prolog ()
         (process-send-string "prolog"
                   "\035nl,write(hello),nl.\n")
     )
     

Upon invoking this function from GNU Emacs, the results of the query are displayed in the Prolog execution buffer. Notice that the Prolog process is called prolog, the query prefix character (ASCII 29) is denoted in an Emacs-Lisp string by the octal escape sequence \035, and the full-stop at the end of the query must be a period followed by a newline character (denoted in an Emacs-Lisp string by the escape sequence \n).

To make things simpler, the interface defines a function called send-prolog, which, given a query string as its one argument, sends that query to the Prolog process, prefixed by the query prefix character and followed by a full-stop. So the above function can be more clearly written as

     (defun to-prolog ()
         (send-prolog "nl,write(hello),nl")
     )
     

WARNING: GNU Emacs should only send a prefixed query to Prolog when Prolog is waiting for the user to type a term at the terminal. Note that this occurs not only when the user explicitly calls read/[1,2] but also when Prolog is at the top-level prompt.