!7 static JTextArea ta; static L usedConcepts; static new L facts; p-substance { aiEnhancements(); usedConcepts = findAIConcepts( "rplldtbwbbnlrotj kjuwvfidiwmbjsuc xzhtvnqwzuuzixci mibnjwgfxnetaxyz cdtwmxtqspigpyap kdpoqkaoypqenusd"); facts = clParseAll(linesToCL([[ "!" is a typical first word in a program. "Hello" is a typical first word in a letter. cdtwmxtqspigpyap confirms mibnjwgfxnetaxyz. ]])); ta = showText(""); onChangeAndNow(ta, r { fS text = getText(ta); thread { think(text); } }); requestFocus(ta); } sS firstWord(S s) { if (empty(s)) ret ""; if (isLetterOrDigit(first(s))) ret takeCharsWhile(s, f isLetterOrDigit); else ret "" + first(s); } svoid think(S text) { time { S w = firstWord(text); S x = aGlobalID(); /* w is the first word in x. Is x a letter (1) or a program (2)? */ S riddle = quote(w) + " is the first word in " + x + ". Is " + x + " a letter (1) or a program (2)?"; L localFacts = concatLists(facts, clParse(sentencesToCL(riddle))); pcall-short { int answer = solveRiddle(localFacts); print("Answer: " + (answer == 1 ? "letter" : answer == 2 ? "program" : "?")); } } } static L sentencesToCL(S text) { ret listToCL(splitIntoSentences(text)); } static L linesToCL(S text) { ret listToCL(toLinesFullTrim(text)); } static L listToCL(L l) { englishToConceptLanguage_concepts.set(usedConcepts); new L out; print("Have " + n(l, "sentence")); for (S line : l) { S c = englishToConceptLanguage(line); print(line + " => " + c); out.add(c); } ret out; } static int solveRiddle(L facts) { // Find the question Lisp q = findHead(facts, "rplldtbwbbnlrotj"); if (q == null) fail("No question found"); ret 0; // dunno }