Tue 27 Aug 00:14:56 CEST 2024

This commit is contained in:
sbosse 2024-08-27 00:15:05 +02:00
parent 2c5d04c488
commit 4174155bad

44
test/test-logic.js Normal file
View File

@ -0,0 +1,44 @@
var session = logic.create(null , function (msg) {
console.log(msg);
});
var db = [
'event(music).',
'event(theatre).',
'event(poetry).',
'event(stage).',
'event(guided_tour).',
'music(ev0001).',
'music(ev0002).',
'theatre(ev0003).',
'ort(ev0001,bremen).',
'ort(ev0003,bremen).',
'ort(ev0002,hamburg).',
'event_in(Ort,X) :- (music(X);theatre(X)),ort(X,Ort).',
]
var t0=time();
var parsed=session.consult(db.join('\n'));
print('consult',time()-t0,'ms');
print(parsed);
function answer(query) {
parsed=session.query(query);
print(parsed);
var result,results=[],error;
do {
session.answer(function (_result) {
result=_result;
if (result) {
var output=result.toString();
if (output.contains('throw(error')) {
return error=result.args[0].args;
}
if (output=='{}') output='true';
else output=output.replace(/{|}/g,'').replace(/\//,' = ');
results.push(output);
}
});
} while (result);
return results;
}
print(answer('event(X).'))
print(answer('event_in(bremen,X).'))