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

45
LINES

< > BotCompany Repo | #1025521 // The AI Can v2 [dev.]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 5909K of libraries. Click here for Pure Java version (9818L/51K).

!7

set flag AllowMetaCode.

standardBot1 TheAICan_v2 {
  allServers {
    static noeq record Procedure(S text) extends HasGlobalID {
    }
    
    static noeq record Entry(S text) extends HasGlobalID {
      new L<Procedure> how;
    }
  }
  
  Map<S, Entry> db = ciMap();
  
  S add(S s) {
    if (!db.containsKey(s)) { db.put(s, new Entry(s)); change(); ret "OK, stored"; }
    ret "I know";
  }
  S remove(S s) { ret db.remove(s) != null ? with(r change, "OK, then not") : "I know"; }
  
  S listWithPattern(S pat) {
    ret or2(lines(mapValuesToList(db, x -> discord_prependGlobalID(x) + format_ellipsis(pat, x.text)
      + appendBracketed(nMethods(x.how))
    )), "nothing");
  }

  sync S processSimplifiedLine(S s, O... _) {
    try answer super.processSimplifiedLine(s, _);
    new Matches m;
    
    meta {
      S program = [[
        The AI can ... = +
        The AI can't actually ... = -
        What can the AI do = listWithPattern("The AI can ...")
      ]];
      ret ai_lineEquationsToMatchX2Statements(jreplace_multi(program,
        "+", "add(\\$1);",
        "-", "remove(\\$1);"));
    }
    null;
  }
}

Author comment

Began life as a copy of #1025493

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1025521
Snippet name: The AI Can v2 [dev.]
Eternal ID of this version: #1025521/7
Text MD5: b75de35ff26eb709962432f07f1558f6
Transpilation MD5: 734325dc0c191861338ec0cf5b4b4e34
Author: stefan
Category: javax / a.i.
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-10-01 19:19:46
Source code size: 1173 bytes / 45 lines
Pitched / IR pitched: No / No
Views / Downloads: 209 / 308
Version history: 6 change(s)
Referenced in: [show references]