!7 set flag DynModule. sclass CalculationBot > DynPrintLog { bool debug; LS entities = synchroList(); LS facts = synchroList(); SS questions = synchroCIMap(); L rules; L externalFacts; start { loadFunctions_preferCached(); dm_useLocallyCopiedMechLists(); Pair, LS> p = ai_activeRulesAndFacts(); rules = p.a; rules.addAll(ai_parseRules(mL_raw("Data structures [Script]"))); //print("Have rules:"); //pnl(rules); externalFacts = p.b; entities.add("the dawn of time"); new Thinking().step(); print("done"); } S evalExp(Exp e, NLLogicChecker_v2.Matching m) { S code = nlLogic_text(e); print("Eval'ing: " + code); S result = str(evalWithDollarVars(code, m.matches)); print("Result: " + shorten(result, 100)); ret result; } class Thinking { void step { final new NLLogicChecker_v3 c; c.entities = entities; c.evaluator = func(Exp e, NLLogicChecker_v2.Matching m) -> S { evalExp(e, m) }; c.facts = concatLists(facts, externalFacts); applyNLLogicFacts_v4(c, voidfunc(IfThen rule, NLLogicChecker_v2.Matching m) { // Rule fired! print("Firing rule " + rule.globalID); executeRule(c, RuleWithParams(rule, m.matches)); }, rules); } void executeRule(NLLogicChecker_v3 c, RuleWithParams r) { // Execute rule for (Exp e : nlLogic_unrollAnd(r.rule.out)) { e = c.apply(e, r.matches); if (e cast Func) { S name = e.name; if (eq(name, 'fact)) { S fact = nlLogic_text(e.arg); if (!containsNL(facts, fact)) facts.add(fact); } else if (eq(name, 'entity)) { S ent = nlLogic_text(e.arg); if (!containsNL(entities, ent)) { entities.add(ent); print("New entity: " + ent); } } /*else if (eq(name, 'input)) { S x = nlLogic_text(e.arg); if (!rewrittenInputs.contains(x) && newRewrittenInputs.add(x)) print("New rewritten input: " + x); } */else ret with print("Skipping rule with unknown RHS func: " + e.name); } else ret with print("Skipping rule with unknown RHS element: " + e); } } } // end class Thinking }