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