tau-prolog
tau-prolog copied to clipboard
Access Tau Prolog via pipes or sockets
Is there a way to interact with Tau Prolog via pipes or sockets?
For example, I would like to automatically send ISO test cases to Tau Prolog, and see how the system responds:
http://www.complang.tuwien.ac.at/ulrich/iso-prolog/conformity_testing
There are Emacs definitions that let us automate this, assuming that we can send these test cases to the system somehow.
If possible, please consider providing such an interface, so that a query can be automatically sent to Tau Prolog, and we can obtain the system's answer for example via a network connection. Thank you!
Have you tried the version of Node.js? You can do a simple script in Node.js for running queries from the command line.
var pl = require( "tau-prolog" );
var query = process.argv[2] || "true.";
var max_answers = process.argv[3] || 100;
var session = pl.create(5000);
session.query(query);
session.answers(x => console.log(pl.format_answer(x)), max_answers);
$ nodejs query "X = a ; X = b."
X = a ;
X = b ;
false.
Would it be enought?
This is definitely a good first step, thank you a lot! However, if I understand this correctly, it would require shell-escaping the example queries. This adds an additional source of potential issues.
For example, test case #259 requires to post the following query:
X = 0'\ +'/*'. %*/1.
This contains a backslash, a newline, and also single quotes. There are also test cases that require to post double-quotes and tokens that potentially have other meanings in a shell context.
If possible, I would prefer a version where we can paste a given text, literally, on the toplevel. Is the toplevel accessible from Node.js?
Mmm... Could you write the test cases into files?
Yes, I could do this, if it helps.
For illustration, a very good way to systematically go through all these test cases is using Emacs with a few simple definitions. Here is a video that shows this:
https://www.metalevel.at/prolog/videos/conformity_testing
With Emacs, everything can be automated, including writing the test cases to a file if this helps. The important point is to reliably get the intended test cases somehow to Tau Prolog, and then to reliably obtain the result so that it can be shown in the Emacs buffer, and compared with the expected result.
Hi @triska. Sorry for the delayed response.
The following script creates a simple REPL that will allow you to execute goals as you do in your video.
var readline = require("readline");
var pl = require( "tau-prolog" );
var session = pl.create(5000);
var max_answers = process.argv[2] || 100;
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
rl.on('line', function(query) {
if(query.length > 0) {
var parsed = session.query(query);
if(parsed === true)
session.answers(x => console.log("\n" + pl.format_answer(x, session)), max_answers);
else
console.log(pl.format_answer(parsed, session));
}
});
If you need to enter multi-line inputs, you can try something like this:
var fs = require("fs");
var pl = require("tau-prolog");
var session = pl.create(5000);
var max_answers = process.argv[2] || 100;
while(true) {
var data = fs.readFileSync(0, "utf-8");
var query = data.toString();
var parsed = session.query(query);
if(parsed === true)
session.answers(x => console.log("\n" + pl.format_answer(x, session)), max_answers);
else
console.log(pl.format_answer(parsed, session));
}
Example:
$ nodejs taupl
X = a,
Y = b.
X = a, Y = b.
p.
uncaught exception: error(existence_error(procedure, '/'(p, 0)), '/'(top_level, 0))
write('a
b').
a
b
true.
The following script creates a simple REPL that will allow you to execute goals as you do in your video.
Maybe provide this simple script emulating a REPL as part of the Tau Prolog distribution? It would simplify quick tests without searching for this code among all the issues or writing yet another version for it from scratch. In alternative could be to add this sample code to the documentation available in the website.