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

32
LINES

< > BotCompany Repo | #1025793 // philosophyBot_autoJava

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (14668L) is out of date.

1  
// supports max 3 arguments so far
2  
3  
// example use:
4  
//   java gazelle_guilds
5  
//
6  
//   proc {
7  
//     for $guild in gazelle_guilds():
8  
//       say (I am in guild $guild)
9  
//   }
10  
11  
svoid philosophyBot_autoJava(PhilosophyBot1 bot) {
12  
  bot.addFactPreprocessor(s -> {
13  
    LS tok = bot.mainTokenize(s);
14  
    if (countTokens(tok) == 2 && eq(firstToken(tok), "java")) {
15  
      S name = secondToken(tok);
16  
      if (!isIdentifier(name)) ret false;
17  
      print("Importing java function " + name);
18  
      if (!canCallAndMakeFunctionNamed(name))
19  
        ret false with print("Warning: Java function not found: " + name);
20  
      bot.addNativePredicate(name + "()",
21  
        () -> callAndMake(name));
22  
      bot.addNativePredicate(name + "($a)",
23  
        map -> callAndMake(name, unquote(map.get("$a"))));
24  
      bot.addNativePredicate(name + "($a, $b)",
25  
        map -> callAndMake(name, unquote(map.get("$a")), unquote(map.get("$b"))));
26  
      bot.addNativePredicate(name + "($a, $b, $c)",
27  
        map -> callAndMake(name, unquote(map.get("$a")), unquote(map.get("$b")), unquote(map.get("$c"))));
28  
      true;
29  
    }
30  
    false;
31  
  });
32  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1025793
Snippet name: philosophyBot_autoJava
Eternal ID of this version: #1025793/5
Text MD5: 9fdadaf2432c4cf6b23f665aae1ccd3f
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-18 15:42:53
Source code size: 1137 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 238 / 373
Version history: 4 change(s)
Referenced in: [show references]