tau-prolog won't run a prolog code that I use CHR library in although it works on SWI-Prolog

233 Views Asked by At

I'm trying to use Tau Prolog to run a CHR code and it gives this error:

throw(error(existence_error(procedure, '/'(color, 1)), '/'(top_level, 0)))

although it works fine on SWI Prolog.

This is the Prolog code:

:- use_module(library(chr)).

:- chr_constraint(color/1).

color(X), color(Y) <=> mix(X,Y,Z) | color(Z).

color(brown) \ color(_) <=> true.

mix(red,blue,purple).
mix(blue,yellow,green).
mix(yellow,red,orange).

this is the query I run:

?- color(yellow), color(red).

This is the JS code I use to run Tau Prolog:

let res2 = "";
let callbackStr = true;
function postQuery(str) {
  res2 += str + "\n";
  if (str == false)
    callbackStr = false;
}

router.post("/runQuery", async (req, res) => {
  res2 = "";
  let session = pl.create();
  let call = postQuery;
  let query = req.body.sentQuery;
  session.consult(req.body.codeString);
  session.query(query);
  while (callbackStr == true) {
    session.answer(call);
  }
  res.send(res2);
  res2 = "";
  callbackStr = true;
});
1

There are 1 best solutions below

2
CapelliC On

I think you have little chance of success with :-use_module(library(chr))., at least if nobody ported the code from other more mature Prologs to TAU-Prolog

But Falco Nogatz has a Javascript implementation of CHR that could help you.

As I see it, Prolog and CHR overlap (well, Prolog is larger), so using a different host language for your CHR rules could be easy - and convenient.