!7 concept Word { S text; long lastUsed; } p { db(); botSleep("Word Holder."); } synchronized answer { if (matchOneOf(s, "words", "list")) ret struct(wordsByLastUse()); if "size" ret str(countConcepts(Word)); if "add words *" { ret "OK, " + addWords(javaTokC($1)) + " new"; } } static L wordsByLastUse() { ret collect(sortByFieldDesc(list(Word), "lastUsed"), "text"); } // return number of new words static int addWords(L words) { long lastUsed = now(); int n = 0; for (S text : words) { Pair p = uniq2(Word, +text); if (p.b) ++n; cset(p.a, +lastUsed); } ret n; }