我正在尝试使用 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;
});