2017-09-18 4 views
0

1) Ich brauche eine Möglichkeit, die Frage zu wiederholen, wenn die Benutzereingabe anders als ja/nein war?CLIPS Programmierung erklärt benötigt

2) Ich brauche eine Möglichkeit, CLIPS kleine und Großbuchstaben zu akzeptieren.

Ich fand dieses Beispiel von googling, aber ich bin nicht so sicher, wie es auf bestimmten Linien funktioniert. Kann mir jemand erklären, wie das geht? Oder es gibt einen besseren Weg, beides zu tun, was ich brauchte.

(deffunction ask-question (?question $?allowed-values) 
    (printout t ?question) 
    (bind ?answer (read)) 
    (if (lexemep ?answer) 
     then (bind ?answer (lowcase ?answer))) 
    (while (not (member ?answer ?allowed-values)) do 
     (printout t ?question) 
     (bind ?answer (read)) 
     (if (lexemep ?answer) 
      then (bind ?answer (lowcase ?answer)))) 
    ?answer) 

(deffunction yes-or-no-p (?question) 
    (bind ?response (ask-question ?question yes no y n)) 
    (if (or (eq ?response yes) (eq ?response y)) 
     then yes 
     else no)) 

Antwort

1

Der Pseudo-Code für die ask-Frage-Funktion:

Print the question. 
Get the answer. 

If 
    The answer is a symbol or string 
Then 
    Convert the answer to lower case. 
End if 

While the answer is not one of the allowed values 

    Print the question. 
    Get the answer. 

    If 
    The answer is a symbol or string 
    Then 
    Convert the answer to lower case. 
    End if 

End while 

Return the answer.