!747 m { static S question = "Is port 80 open?"; static class ThePortOracle { static S isPort_open(S s) { int port = parseInt(s); print("I'll check port " + port + "..."); boolean b = isPortOpen(port); return b ? "Yes, it is open!" : "No, it is not open."; } } // pattern, class name, method static String[][] entries = { {"is port * open", "ThePortOracle", "isPort_open"} }; static S answerQuestion(S question) { L tok = parse(question); for (S[] e : entries) { S[] m = match2(parse(e[0]), tok); if (m != null) ctex { Class c = Class.forName("main$" + e[1]); return "" + call(c, e[2], (Object[]) m); } } return unknown(question); } static S unknown(S question) { return "? Unknown question: " + question; } p { if (args.length != 0) question = join(" ", args); print("Q: " + question); S answer = answerQuestion(question); print("A: " + answer); } static L parse(S s) { return tokensToLowerCase(dropPunctuation(javaTokPlusPeriod(s))); } }