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

34
LINES

< > BotCompany Repo | #1021895 // gazelle_addCalculationFunctionsToRules

JavaX fragment (include)

scope gazelle_addCalculationFunctionsToRules.

sclass #Calculator {
  S var1, var2, var3;
  O function; // func(double, double) -> double
  bool debug;
 
  *() {}
  *(S *var1, S *var2, S *var3, O *function, bool *debug) {}
  
  SS get(SS map, LS tokC, LS tokI, RuleEngine2_MatchedRule matched) {
    if (map == null) null;
    double result;
    try {
      S value1 = getOrKeep(map, var1), value2 = getOrKeep(map, var2);
      result = (double) callAndMake_orF2(function, parseDouble(value1), parseDouble(value2));
    } catch {
      ret null;
    }
    if (!strictPutIC(map, var3, str(iround(result)))) null;
    ret map;
  }
}

svoid gazelle_addCalculationFunctionsToRules(RuleEngine2 engine, O... _) {
  bool debug = boolPar debug(_) || boolPar calcDebug(_);
  for (final RuleEngine2.Rule r : engine.rules)
    for (Matches m : getJMatches_all("compute var * from * and * using *", r.comments)) {
      r.addMapMassager(new Calculator($2, $3, $1, $4, debug));
      if (debug) print("Calculator made");
    }
}

end scope

Author comment

Began life as a copy of #1021872

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1021895
Snippet name: gazelle_addCalculationFunctionsToRules
Eternal ID of this version: #1021895/8
Text MD5: 8a06edc9dc8c7510447c339d42340ce7
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-03 00:49:10
Source code size: 1059 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 260 / 306
Version history: 7 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)