static new ThreadLocal<Bool> applyNLLogicFacts_v4_iterate_steppable_verbose;

static SplittableSteppable applyNLLogicFacts_v4_iterate_steppable(final NLLogicChecker_v2 c, final VF2<IfThen, NLLogicChecker_v2.Matching> onRuleFired, final VF4<IfThen, NLLogicChecker_v2.Matching, L<Exp>, Exp> onRuleFailed, L<IfThen> rules) {
  c.rules = rules;
  final bool verbose = isTrue(applyNLLogicFacts_v4_iterate_steppable_verbose!);
  ret splittableSteppable_forEach(rules, voidfunc(final IfThen rule) { pcall {
    final new NLLogicChecker_v2.Matching m;
    m.verbose = verbose;
    if (verbose)
      print("Checking rule (iterating): " + rule);
    nlLogic_iterate_withOnFail2(c, rule.in, m, new L, r {
      if (verbose) {
        print("Matched " + quote(c.input) + " with rule " + quote(rule));
        printStruct("  ", m.matches);
      }
      callF(onRuleFired, rule, m);
    }, voidfunc(L<Exp> satisfiedConditions, Exp e) {
      callF(onRuleFailed, rule, m, satisfiedConditions, e)
    });
  }});
}