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

28
LINES

< > BotCompany Repo | #1008135 // applyRule_random

JavaX fragment (include)

svoid applyRule_random(S ruleID) {
  // process the rule
  Lisp rule = getLispTruth(ruleID);
  if (rule == null) { print("Rule not found: " + ruleID); ret; }
  //print("Applying rule " + ruleID);
  print_setPrefixForThread(ruleID + "> ");
  try {
    L<Lisp> conditions = dropLast(rule.args);
    Lisp out = last(rule.args);
    //for (Lisp cond : conditions) print("Condition: " + cond);
      
    new Map<S, Lisp> matches;
    int n = matchConditions_random(conditions, matches);
    if (n == -1) {
      print("Yo! " + struct(matches));
      out = lispReplaceVars(out, matches);
      if (lispTrue(out))
        print("Already had: " + out);
      else {
        print("Defining: " + lispToEnglish_prettier(out));
        emit(out, ruleID);
      }
    } else
      print("Only " + n + " of " + n(conditions, "condition") + " met");
  } finally {
    print_setPrefixForThread("");
  }
}

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: #1008135
Snippet name: applyRule_random
Eternal ID of this version: #1008135/1
Text MD5: 4db969f58581fd44b695e0a89a07080e
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-25 16:41:35
Source code size: 920 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 472 / 488
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1008137 - applyRule_all_random - choose one of all solutions