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

34
LINES

< > BotCompany Repo | #1021895 // gazelle_addCalculationFunctionsToRules

JavaX fragment (include)

1  
scope gazelle_addCalculationFunctionsToRules.
2  
3  
sclass #Calculator {
4  
  S var1, var2, var3;
5  
  O function; // func(double, double) -> double
6  
  bool debug;
7  
 
8  
  *() {}
9  
  *(S *var1, S *var2, S *var3, O *function, bool *debug) {}
10  
  
11  
  SS get(SS map, LS tokC, LS tokI, RuleEngine2_MatchedRule matched) {
12  
    if (map == null) null;
13  
    double result;
14  
    try {
15  
      S value1 = getOrKeep(map, var1), value2 = getOrKeep(map, var2);
16  
      result = (double) callAndMake_orF2(function, parseDouble(value1), parseDouble(value2));
17  
    } catch {
18  
      ret null;
19  
    }
20  
    if (!strictPutIC(map, var3, str(iround(result)))) null;
21  
    ret map;
22  
  }
23  
}
24  
25  
svoid gazelle_addCalculationFunctionsToRules(RuleEngine2 engine, O... _) {
26  
  bool debug = boolPar debug(_) || boolPar calcDebug(_);
27  
  for (final RuleEngine2.Rule r : engine.rules)
28  
    for (Matches m : getJMatches_all("compute var * from * and * using *", r.comments)) {
29  
      r.addMapMassager(new Calculator($2, $3, $1, $4, debug));
30  
      if (debug) print("Calculator made");
31  
    }
32  
}
33  
34  
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: 259 / 306
Version history: 7 change(s)
Referenced in: [show references]