Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

37
LINES

< > BotCompany Repo | #1008134 // applyRule_all - full rule application

JavaX fragment (include)

sbool applyRule_all_debug;

static void applyRule_all(S ruleID) {
  // process the rule
  Lisp rule = getLispTruth(ruleID);
  if (rule == null) { print("Rule not found: " + ruleID); ret; }
  //print("Applying rule " + ruleID);
  if (applyRule_all_debug) print_setPrefixForThread(ruleID + "> ");
  try {
    applyRule_all(rule, ruleID);
  } finally {
    if (applyRule_all_debug) print_setPrefixForThread("");
  }
}

svoid applyRule_all(Lisp rule, S ruleID) {
  L<Lisp> conditions = dropLast(rule.args);
  Lisp out = last(rule.args);
  //for (Lisp cond : conditions) print("Condition: " + cond);
    
  L<Map<S, Lisp>> results = matchConditions_all(conditions, new HashMap);
  if (applyRule_all_debug) {
    print("Got " + n(results, "results"));
    if (empty(results))
      print("  " + n(matchConditions_random(conditions, new HashMap), "conditions") + " met of " + l(conditions));
  }
  for (Map<S, Lisp> matches : results) {
    if (applyRule_all_debug) print("Yo! " + struct(matches));
    out = lispReplaceVars(out, matches);
    if (lispTrue(out)) {
      if (applyRule_all_debug) print("Already had: " + out);
    } else {
      if (applyRule_all_debug) print("Defining: " + lispToEnglish_prettier(out));
      emit(out, ruleID);
    }
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1008134
Snippet name: applyRule_all - full rule application
Eternal ID of this version: #1008134/7
Text MD5: 93f9b1338c7567c668632b98c79af16e
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-04-29 18:23:58
Source code size: 1286 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 425 / 448
Version history: 6 change(s)
Referenced in: [show references]