!759 static S codeSnippetID = "#1002745"; static Lisp code; static new L memory; static new L log; p { code = snlToTree(loadSnippet(codeSnippetID)); print(getProgramID() + ": parse result = " + code); load("memory"); } static Lisp snlMatchFirst(Lisp pat, L list, SNLMatches m) { for (Lisp l : list) if (snlMatch2(pat, l, m)) ret l; ret null; } static Lisp scanMem(Lisp pat, SNLMatches m) { ret snlMatchFirst(pat, memory, m); } static Lisp scanMem(S pat, SNLMatches m) { ret snlMatchFirst(snlToTree_cached(pat), memory, m); } static void memorize(Lisp l) { if (!memory.contains(l)) { memory.add(l); save("memory"); } } static boolean yo(Lisp snl, SNLMatches m) { if (scanMem(snl, m) != null) ret true; if (snlMatch2("i < don't < know < X", snl, m)) ret scanMem("* < said < X < is < *", m) == null; // TODO: vars probably don't work ret false; } !include #1002750 // new LThread static Lisp runSingle(Lisp statement, Lisp code) { log.add("runSingle " + code); LThread thread = new LThread(code); thread.log = log; thread.statements.add(statement); print("Statements: " + structure(thread.statements)); ret thread.run() ? first(thread.output) : null; } static Lisp runMulti(Lisp statement, Lisp code) { assertTrue(isJuxta(code)); for (Lisp sub : code) { Lisp l = runSingle(statement, sub); if (l != null) ret l; } ret null; } answer { if (!attn()) ret null; if (match("log " + parseSnippetID(programID()), s)) ret slackSnippet(fromLines(log)); if (match("memory " + parseSnippetID(programID()), s)) ret slackSnippet(structureLines(memory)); log.clear(); // convert to SNL first s = or((S) callOpt/*Safe*/(getBot ("#1002700"), "naiveSNL", s), s); Lisp in = snlToTree(s); Lisp statement = snlToTree("user < says < [" + snlFromTree(in) + "]"); Lisp out = isJuxta(code) ? runMulti(statement, code) : runSingle(statement, code); if (out != null) ret "[SNL: " + snlFromTree(in) + "]\n" + snlToText(out); }