Libraryless. Click here for Pure Java version (7584L/50K/168K).
1 | !7 |
2 | |
3 | concept TheList { |
4 | S name; |
5 | new L<S> entries; |
6 | |
7 | void add(S entry) { |
8 | entries.add(entry); |
9 | change(); |
10 | } |
11 | } |
12 | |
13 | concept Selection { |
14 | TheList list; |
15 | } |
16 | |
17 | static TheList list; |
18 | |
19 | p { |
20 | dbIndexing(TheList, 'name); |
21 | list = uniq(Selection).list; |
22 | if (list == null) selectList("cool things"); |
23 | if (isMainProgram()) botSleep(); |
24 | } |
25 | |
26 | synchronized answer { |
27 | if "select *" { |
28 | selectList($1); |
29 | ret "OK, has " + n(theList().entries, "entry"); |
30 | } |
31 | |
32 | if "which" { |
33 | ret list.name; |
34 | } |
35 | |
36 | if "add *" { |
37 | theList().add($1); |
38 | theList().change(); |
39 | ret "OK, has position " + l(theList().entries); |
40 | } |
41 | |
42 | if "add * at *" { |
43 | int i = parseInt($2)-1; |
44 | theList().entries.add(i, $1); |
45 | theList().change(); |
46 | ret "OK"; |
47 | } |
48 | |
49 | if "remove *" { |
50 | int i = theList().entries.indexOf($1); |
51 | if (i < 0) ret "Not in list"; |
52 | else { |
53 | theList().entries.remove(i); |
54 | theList().change(); |
55 | } |
56 | ret "OK, removed from position " + (i+1); |
57 | } |
58 | |
59 | if "length" |
60 | ret lstr(theList().entries); |
61 | |
62 | if "entry *" { |
63 | S entry = get(theList().entries, parseInt($1)-1); |
64 | ret entry == null ? "Nuttn" : "Entry: " + quote(entry); |
65 | } |
66 | |
67 | if "fix lol" { |
68 | fixLOL(); |
69 | ret "OK"; |
70 | } |
71 | } |
72 | |
73 | static TheList theList() { |
74 | ret list; |
75 | } |
76 | |
77 | svoid selectList(S name) { |
78 | if (!hasConcept(TheList, +name)) { |
79 | lol().add(name); |
80 | lol().change(); |
81 | } |
82 | list = uniq(TheList, +name); |
83 | cset(uniq(Selection), +list); |
84 | } |
85 | |
86 | // the "list of lists" |
87 | static TheList lol() { |
88 | ret uniq(TheList, name := "lol"); |
89 | } |
90 | |
91 | svoid fixLOL { |
92 | lol().entries = collect(list(TheList), 'name); |
93 | lol().change(); |
94 | } |
Began life as a copy of #1009225
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1009226 |
Snippet name: | Core List Bot [should work] |
Eternal ID of this version: | #1009226/13 |
Text MD5: | fade12829c4b02fd799559757e8d5971 |
Transpilation MD5: | 484563b99a450e50dc028ca711a21f98 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-07-19 04:33:28 |
Source code size: | 1687 bytes / 94 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 415 / 544 |
Version history: | 12 change(s) |
Referenced in: | [show references] |