!759 static JList list; static JTextArea chat; static JTextField input; static File logFile; static new L log; static L recommendations; static int listDelay = 2000, listMakingTimeout = 2000; static int maxListLength = 100; static Bool thinking; sclass Gen { S name; O func; *(S *name, O *func) {} public S toString() { ret name; } } p-awt { loadLog(); final L _log = cloneList(log); thread "Scoring!" { print("Yo: " + callF(oneAssoc(dropLast(_log)))); scoreGenerator(_log, "1 assoc"); scoreGenerators(_log); } list = new JList; chat = autoScroll(wordWrapTextArea()); chat.setText(joinLines(log)); input = new JTextField; JFrame frame = showFrame(vgrid(centerAndSouth(chat, input), list)); //setFrameIconLater(frame, "#1003593"); onEnter(input, r { post(); }); onDoubleClick(list, voidfunc(S s) { if (empty(s)) ret; input.setText(s); post(); }); fillList(); input.requestFocus(); } static S getInput() { ret joinLines(" # ", input.getText().trim()); } static void post() { S s = getInput() + "\n"; chat.append(s); appendToFile(logFile, "[" + chatTime() + "] " + s); input.selectAll(); } static void fillList() { bool t = shouldUpdateList(); if (neq(t, thinking)) { thinking = t; setFrameIcon(list, t ? "#1003603" : "#1003593"); } if (!t) againl8r(); else thread "Fill List" { final new L data; makeListData(data); awt { fillListWithStrings(list, data); againl8r(); } } } static void againl8r() { swingAfter(list, listDelay, r { fillList(); }); } static bool shouldUpdateList() { //print("List bounds: " + boundsOnScreen(list)); ret getFrame(list).isFocused() && !mouseInComponent(list); } // also called from outside static L loadLog() { if (logFile == null) logFile = getProgramFile("log.txt"); for (S s : toLines(loadTextFile(logFile))) pcall { log.add(substring(s, s.indexOf(']')+1).trim()); } ret log; } // also called from outside static void recommendSolver(S solverID) { if (!isRecommendedSolver(solverID = fsi(solverID))) { print("Adding recommended solver: " + solverID); logQuoted("recommendations.txt", solverID); } else print("Solver already recommended: " + solverID); } static bool isRecommendedSolver(S solverID) { ret contains(scanLog("recommendations.txt"), fsI(solverID)); } static void makeListData(L l) { try { new L gens; makeGenerators(gens, log); if (empty(gens)) { l.add("No generators"); ret; } long timeout = now() + listMakingTimeout; int i = -1; new HashSet seen; while (now() < timeout && l(l) < maxListLength && nempty(gens)) { i = (i+1) % l(gens); Gen gen = gens.get(i); try { S s = cast callF(gen.func); if (empty(s) || seen.contains(s)) gens.remove(i); else { seen.add(s); l.add(s); } } catch { gens.remove(i); } } } catch e { printStackTrace(e); l.add(e.toString()); } } // VERIFICATION PART static void scoreGenerators(L log) { new MultiSet scores; for (int i = 1; i <= l(log); i++) scoreGenerators1(subList(log, 0, i), scores); print(asciiHeading2("SCORES")); for (S name : scores.getTopTen()) print(" [" + scores.get(name) + "] " + name); print(); } static void scoreGenerators1(L log, MultiSet scores) { if (empty(log)) ret; S line = last(log); log = dropLast(log); new L gens; makeGenerators(gens, log); for (Gen gen : gens) { try { if (eq(callF(gen.func), line)) scores.add(gen.name); } catch {} } } static S callSingle(L log, O genName) { new L gens; makeGenerators(gens, log); Gen gen = findByField(gens, "name", genName); if (gen == null) null; ret (S) callF(gen.func); } static bool verifySingle(L log, O genName) { if (empty(log)) false; S line = last(log); log = dropLast(log); new L gens; makeGenerators(gens, log); Gen gen = findByField(gens, "name", genName); if (gen == null) false; try { if (eq(callF(gen.func), line)) true; } catch {} false; } static void scoreGenerator(L log, S genName) { for (int i = 1; i < l(log); i++) { S expect = log.get(i); S s = callSingle(subList(log, 0, i), genName); bool ok = eq(s, expect); if (ok) print(genName + " OK: " + expect); else print(genName + " NO [" + s + "]: " + expect); } } // CREATIVE PART! // put func {}'s returning a string in there static void makeGenerators(L l, final L log) { gen(l, "hello random", func { "Hello " + randomID(10) }); gen(l, quine(func { last(log) })); gen(l, quine(func { oneOf(log) })); gen(l, "1 assoc", oneAssoc(log)); gen(l, "most popular", mostPopular(log)); addLoadedSolvers(l); } svoid addLoadedSolvers(L l) { if (recommendations == null) { recommendations = new L; for (S s : scanLog("recommendations.txt")) if (isSnippetID(s)) recommendations.add(s); } for (final S solverID : recommendations) gen(l, solverID, func { O c = hotwireCached(solverID); ret call(c, "calc", log); }); } static O oneAssoc(final L log) { ret func { for (int i = l(log)-2; i >= 0; i--) if (eqic(log.get(i), last(log))) ret log.get(i+1); null; }; } static O mostPopular(final L log) { ret func { ret new MultiHashSet(log).getMostPopularEntry(); }; }