(defrule one-y (one y) => (printout t " " crlf) (printout t "問題一.你認為你是一個有個性,有自己的思想及主見的人嗎?(y/n)") (bind ?yn (read)) (assert (gquestion1 ?yn)))改為
(defrule one-y (one y) => (printout t " " crlf) (read-from-web "問題一.你認為你是一個有個性,有自己的思想及主見的人嗎?(y/n)" gquestion1))經過servlet的處理, assert an ordered fact: (gquestion1 y)。函式 read-from-web 的設計如下:
(deffunction read-from-web (?prompt ?factName) (printout t ?prompt) (printout t "<FORM METHOD=POST ACTION=http://" ?*host* "/servlets/JessServlet>") (printout t "<INPUT TYPE=\"hidden\" NAME=\"fileRB\" VALUE=\"com\">") (printout t "<INPUT TYPE=\"hidden\" NAME=\"fact_name\" VALUE=" ?factName ">") (printout t crlf "<INPUT TYPE=\"radio\" NAME=\"slot\" VALUE=\"n\" checked>no") (printout t "<INPUT TYPE=\"radio\" NAME=\"slot\" VALUE=\"y\" >yes") (printout t crlf crlf "<p><INPUT TYPE=submit VALUE=\"Enter\">") (printout t "</FORM>") )
(defrule QUESTIONS::ask-a-question ?f <- (question (already-asked FALSE) (the-question ?the-question) (attribute ?the-attribute) (valid-answers $?valid-answers)) => (modify ?f (already-asked TRUE)) (read-from-web ?the-question ?the-attribute ?valid-answers) (halt) (set-current-module QUESTIONS) ; to keep answer in the same module )