!include once #1027630 // Msg static transformable record LogicRule(lhs, rhs) {} cmodule NewEngineSpike > DynPrintLog { L msgs; bool verbose = true, printNonMatches = true; start-thread { if (empty(msgs)) setField(msgs := mainCruddieLog()); print("Have " + nMessages(msgs)); pnlStruct(takeFirst(2, msgs)); L msgs2 = whereFieldIsTrue fromUser(msgs); new L props; for (Msg msg : takeFirst(5, msgs2)) print(addAndReturn(props, ll(msg, "was understood correctly"))); props.add(print(ll(get(msgs2, 5),"is a wrong recognition"))); O pat = ll("$x", "was Understood correctly"); for (O prop : props) { print(prop); print(" => " + mapToStringWithSize(deepZip(pat, prop))); } } Map deepZip(O a, O b) { ret newGazelle_deepZip1(a, b); } void applyLogicRuleToFact(LogicRule rule, O fact) { O cond = rule.lhs, rhs = rule.rhs; // now we match the fact to our condition SS map = deepZip(cond, fact); if (map == null) ret with if (printNonMatches) print("Non-match: " + quote(cond) + " / " + quote(fact)); // Now we have a proper mapping with the keys being variables! if (verbose) print("Match: " + quote(cond) + " / " + quote(fact)); // Apply mapping to right hand side O rhs_replaced = replaceVars(rhs, map); if (verbose) print(+rhs_replaced); Map trail = litorderedmap(op := "applyLogicRuleToFact", +rule, +fact, +rhs_replaced); addRewrittenRHS(rhs_replaced, trail); } O replaceVars(O o, Map map) { ret o; // TODO } void addRewrittenRHS(O rhs, O trail) { print("Derived: " + rhs); } }