sclass NewWoody { Map rulesByName; new L badRules; S lastOutput; BBRule activeRule; *() { rulesByName = indexFieldAsCIMap('listName, bb_allRules()); } *(NewWoody w) { copyFields(w, this, 'rulesByName, 'badRules); } void processInput(S input) { temp tempSetTL(ctxContext_var(), nu(CtxContext, +input)); new L matching; for (BBRule r : valuesList(rulesByName)) { continue unless ruleExpressionMatches(r); matching.add(r); } lastOutput = null; activeRule = first(matching); if (activeRule != null) lastOutput = random(activeRule.answers); } bool ruleExpressionMatches(BBRule r) { continue if empty(r.expression); try { ret ctxEvalCondition(r.expression); } catch print e { badRules.add(r); rulesByName.remove(r.listName); false; } } bool listsMatching(S input) { temp tempSetTL(ctxContext_var(), nu(CtxContext, +input)); ret [BBRule r : valuesList(rules) | ruleExpressionMatches(r)]; } }