!752 static int port = 7654; concepts. concept Definition { S name; // what is defined S text; // definition text O source; // where definition comes from (optional) O caveat; // an optional restriction of the definition, like "maybe" or "allegedly" or "rarely" or smth. *() {} *(S *name, S *text) { change(); } } p { useProgramDirOf("#1005059"); concepts(); serveHttp(port); makeBot("Wiki."); print("Go to http://localhost:\*port*/ to browse Wiki.\nType here to edit. Commands: def \"the topic\" \"the text\". undef \"the topic\"."); } synchronized answer { if "def * *" { S name = $1, text = $2; new Definition(name, text); int count = countConcepts(Definition, +name); ret "Definition saved! Now have " + n(count, "definition") + " for " + quote(name) + "."; } if "undef *" { S x = $1; if (isInteger(x)) ret deleteConcept(parseLong(x)) != null ? "Deleted" : "Nothing to delete"; else ret nempty(deleteConcepts(Definition, name := x)) ? "Deleted" : "Nothing to delete"; } } synchronized html { uri = dropPrefix("/", uri); // serve definition if (startsWith(uri, "!")) { S name = substring(uri, 1); L l = findConceptsWhere(Definition, +name); if (empty(l)) ret fixHTML("No definition found for " + quote(htmlencode(name))); else ret fixHTML( htitle("Wiki: " + htmlencode(name)) + h1(htmlencode(name)) + ul(map(l, func(Definition d) { spanTitle("#" + d.id, htmlencode(d.text)) }))); } // process action if (eq(uri, "add")) { printStruct(params); S name = params.get("word").trim(); S text = params.get("definition").trim(); new Definition(name, text); ret hrefresh("/"); } // serve home page final MultiSet ms = collectMultiSet(list(Definition.class), "name"); L names = sorted(ms.keySet()); ret fixHTML( htitle_h1("A. I. Wiki!") + p("Yo I got definitions for:") + ul(map(names, func(S name) { int count = ms.get(name); //S xinfo = bracketedCount(count); Definition example = findConceptWhere(Definition, +name); S xinfo = " - " + htmlencode(example.text); if (count > 1) xinfo += " +\*count-1*/"; ret ahref("/!" + urlencode(name), htmlencode(name)) + xinfo; })) + h3("Add definition") + hform( htableRaw(ll( ll("Word", htextinput("word")), ll("Definition", htextinput("definition", style := "width: 500px")), ll("", hsubmit()) )) , action := "/add", method := "POST") ); }