1

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;
});
Erik Kaplun
  • 37,128
  • 15
  • 99
  • 111
MahmoudLamei
  • 11
  • 1
  • 2

1 Answers1

3

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.

CapelliC
  • 59,646
  • 5
  • 47
  • 90
  • 1
    @PauloMoura: indeed, if only I would have the time right now, I'd like to try the integration in this answer... Javascript is charming me more every time I dig deeper into it – CapelliC May 30 '20 at 11:21
  • 1
    Thank you very much, gonna try to use it now. Didn't know there was a implementation for CHR directly. – MahmoudLamei May 31 '20 at 22:51