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).

1  
!7
2  
3  
concept TheList {
4  
  S name;
5  
  new L<S> entries;
6  
  void add(S entry) { entries.add(entry); change(); }
7  
}
8  
concept Selection { TheList list; }
9  
static TheList list; // cache of the above
10  
11  
p {
12  
  dbIndexing(TheList, 'name);
13  
  if ((list = uniq(Selection).list) == null) selectList("cool things");
14  
  botIfMain();
15  
}
16  
17  
synchronized answer {
18  
  if "select *" { selectList($1); ret "OK, has " + n(list.entries, "entry"); }
19  
  if "which" ret list.name;
20  
  if "add *" { list.add($1); ret "OK, has position " + l(list.entries); }
21  
  if "add * at *" { int i = parseInt($2)-1; list.entries.add(i, $1); list.change(); ret "OK"; }
22  
  if "remove *" {
23  
    int i = list.entries.indexOf($1); if (i < 0) ret "Not in list";
24  
    list.entries.remove(i); list.change(); ret "OK, removed from position " + (i+1);
25  
  }
26  
  if "length" ret lstr(list.entries);
27  
  if "entry *" { S x = get(list.entries, parseInt($1)-1); ret x == null ? "Nuttn" : "Entry: " + quote(x); }
28  
  if "fix lol" { cset(lol(), entries := collect(list(TheList), 'name)); ret "OK"; }
29  
}
30  
31  
svoid selectList(S name) {
32  
  if (!hasConcept(TheList, +name)) lol().add(name);
33  
  cset(uniq(Selection), list := list = uniq(TheList, +name));
34  
}
35  
36  
// the "list of lists"
37  
static TheList lol() { ret uniq(TheList, name := "lol"); }
38  
39  
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: 623 / 1685
Version history: 13 change(s)
Referenced in: [show references]