1

我正在尝试使用 Tau Prolog 运行 CHR 代码,它给出了这个错误:

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

虽然它在 SWI Prolog 上运行良好。

这是序言代码:

:- 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).

这是我运行的查询:

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

这是我用来运行 Tau Prolog 的 JS 代码:

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;
});
4

1 回答 1

3

我认为你几乎没有成功的机会:-use_module(library(chr)).,至少如果没有人将代码从其他更成熟的 Prolog 移植到 TAU-Prolog

但是 Falco Nogatz 有一个CHR 的 Javascript 实现可以帮助你。

正如我所看到的,Prolog 和 CHR 重叠(好吧,Prolog 更大),因此为 CHR 规则使用不同的宿主语言可能很容易 - 也很方便。

于 2020-05-30T05:42:34.533 回答