!7 cmodule AskMeAQuestion { S question, answer; visualize { if (empty(question)) newQuestion(); JLabel lblQ = dm_fieldLabel('question); componentPopupMenuItem(lblQ, "Suggest question...", r { inputText("Question", question, voidfunc(S s) { setField(question := s) }) }); ret withRightMargin(makeForm2( "Computer question", lblQ, "Human answer", centerAndEastWithMargin(onEnter(dm_fieldTextField('answer), rThread submit), jbutton("Submit", rThread submit)), "", withTopMargin(15, rightAlignedButtons("Ask me something else", rThread newQuestion)))); } S randomWord() { ret randomEnglishWordFromDictionary(); } S makeQuestion() { ret "Is " + randomWord() + " the same as " + randomWord() + "?"; } void newQuestion enter { setFields(answer := "", question := makeQuestion()); programLogStructure(litorderedmap(+question)); vmBus_send('showingQuestion, module(), question); } void submit enter { programLogStructure(litorderedmap(+question, +answer)); vmBus_send('userAnsweredQuestion, module(), question, answer); dm_addQAndA_infoBox(question, answer); newQuestion(); } }