2017-09-18 3 views
0

1) J'ai besoin d'un moyen de répéter la question si l'entrée de l'utilisateur était autre que oui/non?CLIPS Programmation expliquée nécessaire

2) J'ai besoin d'un moyen de permettre au CLIPS d'accepter les lettres minuscules et majuscules.

J'ai trouvé cet échantillon en googlant mais je ne suis pas sûr de savoir comment cela fonctionne sur certaines lignes. Quelqu'un peut-il m'expliquer comment cela fonctionne? Ou il y a un meilleur moyen de faire les deux choses dont j'avais besoin.

(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)) 

Répondre

1

Le pseudo-code de la fonction ask-question:

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.