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

29
LINES

< > BotCompany Repo | #1008136 // applyRule_first

JavaX fragment (include)

// returns true if it fired
static bool applyRule_first(S ruleID) {
  // process the rule
  Lisp rule = getLispTruth(ruleID);
  if (rule == null) { print("Rule not found: " + ruleID); false; }
  //print("Applying rule " + ruleID);
  print_setPrefixForThread(ruleID + "> ");
  try {
    ret applyRule_first(rule, ruleID);
  } finally {
    print_setPrefixForThread("");
  }
}

// ruleID is just as an info parameter to emit()
static bool applyRule_first(Lisp rule, S ruleID) {
  L<Lisp> conditions = dropLast(rule.args);
  Lisp out = last(rule.args);

  L<Map<S, Lisp>> results = matchConditions_all(conditions, new HashMap); // can be optimized
  //print("Got " + n(results, "results"));
  if (empty(results)) false;
  Map<S, Lisp> matches = first(results);
  //print("Yo! " + struct(matches));
  out = lispReplaceVars(out, matches);
  //print("Possibly defining: " + lispToEnglish_prettier(out));
  emit(out, ruleID);
  true;
}

Author comment

Began life as a copy of #1008134

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: #1008136
Snippet name: applyRule_first
Eternal ID of this version: #1008136/7
Text MD5: 00cbebd883f41bb6d20b25a2721456dd
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-30 15:04:20
Source code size: 956 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 434 / 448
Version history: 6 change(s)
Referenced in: [show references]