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

39
LINES

< > BotCompany Repo | #1009228 // Core List Bot [formatted more compactly]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (13540L/94K).

!7

concept TheList {
  S name;
  new L<S> entries;
  void add(S entry) { entries.add(entry); change(); }
}
concept Selection { TheList list; }
static TheList list; // cache of the above

p {
  dbIndexing(TheList, 'name);
  if ((list = uniq(Selection).list) == null) selectList("cool things");
  botIfMain();
}

synchronized answer {
  if "select *" { selectList($1); ret "OK, has " + n(list.entries, "entry"); }
  if "which" ret list.name;
  if "add *" { list.add($1); ret "OK, has position " + l(list.entries); }
  if "add * at *" { int i = parseInt($2)-1; list.entries.add(i, $1); list.change(); ret "OK"; }
  if "remove *" {
    int i = list.entries.indexOf($1); if (i < 0) ret "Not in list";
    list.entries.remove(i); list.change(); ret "OK, removed from position " + (i+1);
  }
  if "length" ret lstr(list.entries);
  if "entry *" { S x = get(list.entries, parseInt($1)-1); ret x == null ? "Nuttn" : "Entry: " + quote(x); }
  if "fix lol" { cset(lol(), entries := collect(list(TheList), 'name)); ret "OK"; }
}

svoid selectList(S name) {
  if (!hasConcept(TheList, +name)) lol().add(name);
  cset(uniq(Selection), list := list = uniq(TheList, +name));
}

// the "list of lists"
static TheList lol() { ret uniq(TheList, name := "lol"); }

static L<S> knownCommands() { ret findSupportedQuestionsInFunctions('answer); }

Author comment

Began life as a copy of #1009226

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1009228
Snippet name: Core List Bot [formatted more compactly]
Eternal ID of this version: #1009228/14
Text MD5: 80d11cd157f08f38c215816c1fdaf9ed
Transpilation MD5: 27f74575f9c952fc25966cdb7efe1e17
Author: stefan
Category: javax / a.i.
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-14 10:45:16
Source code size: 1363 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 621 / 1680
Version history: 13 change(s)
Referenced in: [show references]