CLIPS Programming explained needed

542 Views Asked by At

1) I need a way to repeat the question if the user input was other than yes/no?

2) I need a way to allow CLIPS to accept small and capital letters.

I found this sample by googling but im not so sure how its works on certain lines. Can anyone explained to me how this works? Or there is a better a way to did both of things i needed.

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

There are 1 best solutions below

0
On

The pseudo-code for the ask-question function:

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.