please ask about the "switch" function. I want to achieve the following functions:
(switch ?student
(case (stu1 or stu2 or stu3) then
-------)
(case stu4 then
------))
How to make multiple choices perform the same action?
If you place a function call after the case keyword, then that function call must return the value that follows the switch keyword in order for the actions of the case to be applied. So you can define a helper function that is passed the value following the switch keyword and a list of values for which the case should be applied. If the value is among the values, then just return the value and the case will be applied. If it's not, then just negate the value and then the actions of the case statement will not be applied.
CLIPS (6.31 6/12/19)
CLIPS>
(deffunction oneof (?v $?values)
(if (member$ ?v ?values)
then ?v
else (not ?v)))
CLIPS>
(deffunction grade (?student)
(switch ?student
(case (oneof ?student stu1 stu2 stu3)
then B-)
(case stu4
then A+)))
CLIPS> (grade stu1)
B-
CLIPS> (grade stu2)
B-
CLIPS> (grade stu3)
B-
CLIPS> (grade stu4)
A+
CLIPS>