!7 concept Word { S text; long lastUsed; } p { db(); botSleep("Word Holder."); } synchronized answer { if "list words" ret struct(wordsByLastUse()); if "size" ret countConcepts(Word); if "add words *" { addWords((L) safeUnstruct($1)); ret "OK"; } } 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; }