Libraryless. Click here for Pure Java version (7552L/51K/167K).
1 | !7 |
2 | |
3 | concept Word {
|
4 | S text; |
5 | long lastUsed; |
6 | } |
7 | |
8 | p {
|
9 | db(); |
10 | botSleep("Word Holder.");
|
11 | } |
12 | |
13 | synchronized answer {
|
14 | if (matchOneOf(s, "words", "list")) ret struct(wordsByLastUse()); |
15 | if "size" ret str(countConcepts(Word)); |
16 | if "add words *" { ret "OK, " + addWords(javaTokC($1)) + " new"; }
|
17 | } |
18 | |
19 | static L<S> wordsByLastUse() {
|
20 | ret collect(sortByFieldDesc(list(Word), "lastUsed"), "text"); |
21 | } |
22 | |
23 | // return number of new words |
24 | static int addWords(L<S> words) {
|
25 | long lastUsed = now(); |
26 | int n = 0; |
27 | for (S text : words) {
|
28 | Pair<Word, Bool> p = uniq2(Word, +text); |
29 | if (p.b) ++n; |
30 | cset(p.a, +lastUsed); |
31 | } |
32 | ret n; |
33 | } |
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: | #1008466 |
| Snippet name: | Word Holder [OK] |
| Eternal ID of this version: | #1008466/8 |
| Text MD5: | e87232956cb063713ffdaa5b9d254091 |
| Transpilation MD5: | b7f4f7115c46f6c2db8949af8fd5385e |
| Author: | stefan |
| Category: | javax / a.i. |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2017-05-16 15:20:26 |
| Source code size: | 656 bytes / 33 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 819 / 936 |
| Version history: | 7 change(s) |
| Referenced in: | [show references] |