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)

1  
sbool applyRule_all_debug;
2  
3  
static void applyRule_all(S ruleID) {
4  
  // process the rule
5  
  Lisp rule = getLispTruth(ruleID);
6  
  if (rule == null) { print("Rule not found: " + ruleID); ret; }
7  
  //print("Applying rule " + ruleID);
8  
  if (applyRule_all_debug) print_setPrefixForThread(ruleID + "> ");
9  
  try {
10  
    applyRule_all(rule, ruleID);
11  
  } finally {
12  
    if (applyRule_all_debug) print_setPrefixForThread("");
13  
  }
14  
}
15  
16  
svoid applyRule_all(Lisp rule, S ruleID) {
17  
  L<Lisp> conditions = dropLast(rule.args);
18  
  Lisp out = last(rule.args);
19  
  //for (Lisp cond : conditions) print("Condition: " + cond);
20  
    
21  
  L<Map<S, Lisp>> results = matchConditions_all(conditions, new HashMap);
22  
  if (applyRule_all_debug) {
23  
    print("Got " + n(results, "results"));
24  
    if (empty(results))
25  
      print("  " + n(matchConditions_random(conditions, new HashMap), "conditions") + " met of " + l(conditions));
26  
  }
27  
  for (Map<S, Lisp> matches : results) {
28  
    if (applyRule_all_debug) print("Yo! " + struct(matches));
29  
    out = lispReplaceVars(out, matches);
30  
    if (lispTrue(out)) {
31  
      if (applyRule_all_debug) print("Already had: " + out);
32  
    } else {
33  
      if (applyRule_all_debug) print("Defining: " + lispToEnglish_prettier(out));
34  
      emit(out, ruleID);
35  
    }
36  
  }
37  
}

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: 431 / 454
Version history: 6 change(s)
Referenced in: [show references]