Search code examples
clips

CLIPS PROGRAMMING: How to count how many facts that are 'yes'?


I'm new to clips programming and I'm currently developing an expert system for mental health illness (anxiety). The way how my system works is after the user has answered all the questions such as " Do you have excessive worry? ", "Do you feel lonely ?", "Do you have difficulty breathing?" and so on, the system will print out the output. For example:-

;after the user has input all the question about the symptoms...

(defrule MAIN::s-1
(have-anxiety yes)
(or (age 2)
    (age 3))
(heart_palpitation yes)
(excess_sweating yes)
(body_trembling yes)
(dizzy yes)
(difficult_breath yes)
(afraid_crowd yes)
(panic_attack yes)
(short_breath yes)
(panic_arises yes)
(how_long 2)
=>
(printout t crlf)
(printout t "Solution:")
(printout t crlf)
(printout t "You have panic disorder! Please refer specialist now!!!")
(printout t crlf crlf)
(assert (disorder panic)))

The problem with my system now is let say all the facts are 'yes' then that means the user has a mental disorder. But if only 1 fact is 'no' then the user automatically has no disorder since it does not fill the requirement for the rule to fire. Logically if a person has 9 out of 10 symptoms of a mental illness, that person must have a mental illness.

Therefore, I would like to make a condition such as if the user has 4 or more symptoms, then the user has a mental illness. Thank you in advance!

UPDATED

Below is my full code:-

;;;;;;;;;;;;;;;;;;;;FUNCTION;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deffunction ask-question-number (?question $?allowed-values)
    (printout t ?question)
    (bind ?answer (read))
    (while (not (member$ ?answer ?allowed-values)) do
        (printout t ?question)
        (bind ?answer (read)))
    ?answer)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deffunction number-valid (?question)
    (bind ?response (ask-question-number ?question 1 2 3))
    (if (= ?response 1)
        then 1
    else    (if (= ?response 2)
            then 2
        else 3)
        
    )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deffunction ask-question-number-2 (?question $?allowed-values)
    (printout t ?question)
    (bind ?answer (read))
    (while (not (member$ ?answer ?allowed-values)) do
        (printout t ?question)
        (bind ?answer (read)))
    ?answer)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deffunction number-valid-2 (?question)
    (bind ?response (ask-question-number-2 ?question 1 2))
    (if (= ?response 1)
        then 1
    else 2)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;START RULE;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defrule MAIN::start
    (declare (salience 10))
    =>
    (printout t crlf crlf)
    (printout t "Anxiety Diagnosis Expert System")
    (printout t crlf crlf)
    (assert (have-anxiety (yes-or-no-p "Do you have an excessive anxiety and worry?:"))))

(defrule f-2
    (have-anxiety yes)
    =>
    (printout t "Choose your citizen category:")
    (printout t crlf crlf)
    (printout t "1. Adolescence")
    (printout t crlf)
    (printout t "2. Adult")
    (printout t crlf)
    (printout t "3. Kid")
    (printout t crlf crlf)
;   (printout t "Type number(1/2/3): ")
;   (assert (age (read))))
    (assert (age (number-valid "Type number: "))))

(defrule MAIN::f-3
    (have-anxiety yes)
    =>
    (assert (heart_palpitation (yes-or-no-p "Heart palpitation?:"))))

(defrule MAIN::f-4
    (have-anxiety yes)
    (heart_palpitation yes)
    =>
    (assert (excess_sweating (yes-or-no-p "Excessive sweating?:"))))

(defrule MAIN::f-5
    (have-anxiety yes)
    (heart_palpitation yes)
    =>
    (assert (body_trembling (yes-or-no-p "Trembling on some parts of body?:"))))

(defrule MAIN::f-6
    (have-anxiety yes)
    (heart_palpitation yes)
    =>
    (assert (dizzy (yes-or-no-p "Feeling dizzy?:"))))

(defrule MAIN::f-19
        (have-anxiety yes)
    (heart_palpitation yes)
        =>
        (assert (concentrate (yes-or-no-p "Are you hard to concentrate? "))))

(defrule MAIN::f-20
        (have-anxiety yes)
    (heart_palpitation yes)
        =>
        (assert (uneasy_unrealistically (yes-or-no-p "Always feeling uneasy and thinking unrealistically? "))))

(defrule MAIN::f-21
        (have-anxiety yes)
    (heart_palpitation yes)
    =>
        (assert (muscle_feel_tight (yes-or-no-p "Exposure to triggers causes the muscles to feel tight? "))))

(defrule MAIN::f-8
    (have-anxiety yes)
    (heart_palpitation yes)
    (control_worry no)
    =>
    (assert (afraid_crowd (yes-or-no-p "Afraid of crowded place?:"))))

(defrule MAIN::f-7
    (have-anxiety yes)
    (heart_palpitation yes)
    (control_worry no)
    =>
    (assert (difficult_breath (yes-or-no-p "Difficult at breathing?:"))))

(defrule MAIN::f-9
    (have-anxiety yes)
    (heart_palpitation yes)
    (dizzy yes)
    (afraid_crowd yes)
    (difficult_breath yes)
    (concentrate no)
    (uneasy_unrealistically no)
    (muscle_feel_tight no)
    =>
    (assert (panic_attack (yes-or-no-p "Panic attacks repeat unexpectedly?:"))))

(defrule MAIN::f-10
    (have-anxiety yes)
    (heart_palpitation yes)
    (dizzy yes)
    (concentrate no)
    (uneasy_unrealistically no)
    (muscle_feel_tight no)
    (afraid_crowd yes)
    (difficult_breath yes)
    =>
    (assert (short_breath (yes-or-no-p "Sensation of shortness of breath?:"))))

(defrule MAIN::f-11
    (have-anxiety yes)
    (heart_palpitation yes)
    (dizzy yes)
    (concentrate no)
    (uneasy_unrealistically no)
    (muscle_feel_tight no)
    (afraid_crowd yes)
    (difficult_breath yes)
    =>
    (assert (panic_arises (yes-or-no-p "Panic arises even through the object that triggers panic is not life threatening?:"))))

(defrule MAIN::f-12
    (have-anxiety yes)
    (heart_palpitation yes)
    (dizzy yes)
    (concentrate no)
    (uneasy_unrealistically no)
    (muscle_feel_tight no)
    (afraid_crowd yes)
    (difficult_breath yes)
    =>
    (printout t "How long did this happen:")
    (printout t crlf crlf)
    (printout t "1. less than 1 month")
    (printout t crlf)
    (printout t "2. more than 1 month")
    (printout t crlf crlf crlf)
;   (printout t "Type number(1/2):")
;   (assert (how_long (read))))
    (assert (how_long (number-valid-2 "Type number(1/2):"))))

(defrule MAIN::f-13
    (have-anxiety yes)
    (heart_palpitation no)
    =>
    (assert (major_attachment_figures (yes-or-no-p "Have major attachment figures?:"))))

(defrule MAIN::f-14
    (have-anxiety yes)
    (heart_palpitation no)
    (major_attachment_figures yes)
    =>
    (printout t crlf)
    (printout t "List of symptom:")
    (printout t crlf crlf)
    (printout t "1. Refuse to leave home, go to school, go to work.")
    (printout t crlf crlf)
    (printout t "2. Worry about losing major attachment figures due to illness, disasters, or death.")
    (printout t crlf crlf)
    (printout t "3. Worry about experiencing untoward events (getting lost, being kidnapped, having an accident, becoming ill).")
    (printout t crlf crlf)
    (printout t "4. Reluctance to sleep away from home or sleep away from home.")
    (printout t crlf crlf)
    (printout t "5. Repeated nightmares with separation theme.")
    (printout t crlf crlf)
    (assert (list_symptom (yes-or-no-p "Do you have at least 1 of the symptom?:"))))

(defrule MAIN::f-15
    (have-anxiety yes)
    (heart_palpitation no)
    (major_attachment_figures yes)
    =>
    (assert (worry_separation (yes-or-no-p "Worry about separation?:"))))

(defrule MAIN::f-16
    (have-anxiety yes)
    (heart_palpitation no)
    (major_attachment_figures yes)
    =>
    (assert (nausea (yes-or-no-p "Nausea or vomitting?:"))))

(defrule MAIN::f-17
    (have-anxiety yes)
    (heart_palpitation no)
    (major_attachment_figures yes)
    =>
    (assert (stomach_aches (yes-or-no-p "Stomach aches?:"))))

(defrule MAIN::f-18
    (have-anxiety yes)
    (heart_palpitation no)
    (major_attachment_figures yes)
    =>
    (assert (headache (yes-or-no-p "Headaches?:"))))

(defrule MAIN::s-2-f-12
    (have-anxiety yes)
    (heart_palpitation no)
    (major_attachment_figures yes)
    =>
    (printout t "How long did this happen:")
    (printout t crlf crlf)
    (printout t "1. less than 1 month")
    (printout t crlf)
    (printout t "2. more than 1 month")
    (printout t crlf)
    (printout t "3. more than 6 month")
    (printout t crlf crlf crlf)
;   (printout t "Type number(1/2/3):")
;   (assert (how_long (read))))
    (assert (how_long (number-valid "Type number(1/2/3)?:"))))

(defrule MAIN::f-27
    (have-anxiety yes)
    (heart_palpitation no)
    (major_attachment_figures no)
    =>
    (assert (avoid_social (yes-or-no-p "Avoid social situation?:"))))

(defrule MAIN::f-28
    (have-anxiety yes)
    (heart_palpitation no)
    (major_attachment_figures no)
    =>
    (assert (fear_social (yes-or-no-p "Fear about social situation?:"))))

(defrule MAIN::f-29
    (have-anxiety yes)
    (heart_palpitation no)
    (major_attachment_figures no)
    =>
    (assert (fear_humiliation (yes-or-no-p "Fear of humiliating or embarrassing themselves?:"))))

(defrule MAIN::f-22
    (have-anxiety yes)
    (dizzy no)
    (difficult_breath no)
    (heart_palpitation yes)
    =>
    (assert (fear_not_realistic (yes-or-no-p "Do not realize that your fear is not realistic? "))))

(defrule MAIN::f-23
    (have-anxiety yes)
    (heart_palpitation yes)
    (dizzy no)
    =>
    (assert (trigger_headache (yes-or-no-p "Exposure to triggers causes of frequent headaches/migraines? "))))

(defrule MAIN::f-24
    (have-anxiety yes)
    (heart_palpitation yes)
    (dizzy no)
    =>
    (assert (trigger_intense_anxiety (yes-or-no-p "Exposure to triggers cause intense anxiety? "))))



(defrule MAIN::f-25
    (heart_palpitation yes)
    =>
    (assert (control_worry (yes-or-no-p "Difficult control worry? "))))

(defrule MAIN::f-26-adult-adoles
    (control_worry yes)
    (or (age 1)
        (age 2))
    =>
    (printout t "Do you experience three or more of the following:-")
        (printout t crlf crlf)
        (printout t "1. Restlessness")
        (printout t crlf)
        (printout t "2. Easily fatigue")
        (printout t crlf)
        (printout t "3. Muscle tension")
    (printout t crlf)
    (printout t "4. Hard to concentrate")
        (printout t crlf)
        (printout t "5. Sleep disturbance")
        (printout t crlf crlf)
    (assert (experience (yes-or-no-p "Type (yes/no) : "))))

(defrule MAIN::f-26-kid
    (control_worry yes)
    (age 3)
    =>
    (printout t "Do you experience atleast 1 of the following:-")
        (printout t crlf crlf)
        (printout t "1. Restlessness")
        (printout t crlf)
        (printout t "2. Easily fatigue")
        (printout t crlf)
        (printout t "3. Muscle tension")
    (printout t crlf)
    (printout t "4. Hard to concentrate")
        (printout t crlf)
        (printout t "5. Sleep disturbance")
        (printout t crlf crlf)
    (assert (experience-kid (yes-or-no-p "Type (yes/no) : "))))

(defrule MAIN::s-4-f-12
    (or (experience yes)
        (experience-kid yes))
        =>
        (printout t "How long did this happen:")
        (printout t crlf crlf)
        (printout t "1. less than 6 months")
        (printout t crlf)
        (printout t "2. more than 6 months")
        (printout t crlf crlf crlf)
    (assert (how_long (number-valid-2 "Type number(1/2):"))))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;RESULT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defrule MAIN::s-1
    (have-anxiety yes)
    (or (age 2)
        (age 3))
    (heart_palpitation yes)
    (excess_sweating yes)
    (body_trembling yes)
    (dizzy yes)
    (difficult_breath yes)
    (afraid_crowd yes)
    (panic_attack yes)
    (short_breath yes)
    (panic_arises yes)
    (how_long 2)
    =>
    (printout t crlf)
    (printout t "Solution:")
    (printout t crlf)
    (printout t "You have panic disorder! Please refer specialist now!!!")
    (printout t crlf crlf)
    (assert (disorder panic)))

(defrule MAIN::s-2-1
    (have-anxiety yes)
    (age 2)
    (heart_palpitation no)
    (major_attachment_figures yes)
    (list_symptom yes)
    (worry_separation yes)
    (nausea yes)
    (stomach_aches yes)
    (headache yes)
    (how_long 3)
    =>
    (printout t crlf)
    (printout t "Solution:")
    (printout t crlf)
    (printout t "You have separation anxiety disorder! Please refer specialist now!!!")
    (printout t crlf crlf)
    (assert (disorder separation-anxiety)))
;   (halt))

(defrule MAIN::s-2-2
    (have-anxiety yes)
    (or (age 1)
        (age 3))
    (heart_palpitation no)
    (major_attachment_figures yes)
    (major_attachment_figures yes)
    (list_symptom yes)
    (worry_separation yes)
    (nausea yes)
    (stomach_aches yes)
    (headache yes)
    (how_long 2)
    =>
    (printout t crlf)
    (printout t "Solution:")
    (printout t crlf)
    (printout t "You have separation anxiety disorder! Please refer specialist now!!!")
    (printout t crlf crlf)
    (assert (disorder separation-anxiety)))
;   (halt))

(defrule MAIN::s-3
    (have-anxiety yes)
    (or (age 2)
        (age 3))
    (heart_palpitation yes)
    (excess_sweating yes)
    (body_trembling yes)
    (dizzy no)
    (concentrate yes)
    (uneasy_unrealistically yes)
    (muscle_feel_tight yes)
    (afraid_crowd yes)
    (fear_not_realistic yes)
    (trigger_headache yes)
    (trigger_intense_anxiety yes)
    =>
    (printout t crlf)
        (printout t "Solution:")
        (printout t crlf)
        (printout t "You have phobia disorder! Please refer specialist now!!!")
        (printout t crlf crlf)
        (assert (disorder phobia)))
;   (halt))

(defrule MAIN::s-4-adult-adoles
    (have-anxiety yes)
    (experience yes)
    (or (age 1)
        (age 2))
    (heart_palpitation yes)
    (excess_sweating yes)
    (body_trembling yes)
    (dizzy yes)
    (concentrate yes)
    (uneasy_unrealistically yes)
    (muscle_feel_tight yes)
    (control_worry yes)
    (how_long 2)
    =>
    (printout t crlf)
        (printout t "Solution:")
        (printout t crlf)
        (printout t "You have generalized anxiety disorder! Please refer specialist now!!!")
        (printout t crlf crlf)
        (assert (disorder generalized-anxiety)))
;   (halt))


(defrule MAIN::s-4-kid
    (have-anxiety yes)
    (experience-kid yes)
    (age 3)
    (heart_palpitation yes)
    (excess_sweating yes)
    (body_trembling yes)
    (dizzy yes)
    (concentrate yes)
    (uneasy_unrealistically yes)
    (muscle_feel_tight yes)
    (control_worry yes)
    (how_long 2)
    =>
    (printout t crlf)
        (printout t "Solution:")
        (printout t crlf)
        (printout t "You have generalized anxiety disorder! Please refer specialist now!!!")
        (printout t crlf crlf)
        (assert (disorder generalized-anxiety)))
;   (halt))

(defrule MAIN::s-5
    (have-anxiety yes)
    (or (age 2)
        (age 3))
    (heart_palpitation no)
    (major_attachment_figures no)
    (avoid_social yes)
    (fear_social yes)
    (fear_humiliation yes)
    =>
    (printout t crlf)
    (printout t "Solution:")
    (printout t crlf)
    (printout t "You have social anxiety disorder! Please refer specialist now!!!")
    (printout t crlf crlf)
    (assert (disorder social-anxiety)))
;   (halt))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;FEEDBACK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defrule MAIN::feedback-have-disorder
    (or (disorder panic)
        (disorder separation-anxiety)
        (disorder phobia)
        (disorder generalized-anxiety)
        (disorder social-anxiety))
    =>
    (printout t crlf)
    (printout t "Do you satisfied with the system ?" crlf)
    (printout t "Rate: (1)-Disatisfied")
    (printout t "      (2)-Normal")
    (printout t "      (3)-Satisfied" crlf crlf)
    (assert (feedback (number-valid "Feedback answer : ")))
    (printout t crlf crlf "Thank you, have a nice day!" crlf))

(defrule feedback-no-disorder
    (declare (salience -10000))
    (or (and    (not    (disorder panic|separation-anxiety|phobia|generalized-anxiety|social-anxiety))
        (have-anxiety no))
        (and    (not    (disorder panic|separation-anxiety|phobia|generalized-anxiety|social-anxiety))
        (have-anxiety yes)))
    =>
    (printout t crlf)
    (printout t "Solution:")
    (printout t crlf)       
    (printout t "You have no disorder")
    (printout t crlf crlf)
    (assert (no-disorder yes))

    (printout t crlf)
    (printout t "Do you satisfied with the system ?" crlf)
    (printout t "Rate: (1)-Disatisfied")
    (printout t "      (2)-Normal")
    (printout t "      (3)-Satisfied" crlf crlf)
    (assert (feedback (number-valid "Feedback answer : ")))
    (printout t crlf crlf "Thank you, have a nice day!" crlf))

UPDATED

Let say I create a new deftemplate named generalized-anxiety-list where I want to store only generalized anxiety symptom. Then I create a new defrule which will check if there are only symptoms for generalized anxiety:

    (defrule check-s-5
;all these symptoms MUST be a condition
    (symptom (name have-anxiety) (value yes))
    (symptom (name heart-palpitation) (value no))
    (symptom (name major-attachment-figures) (value no))
    (symptom (name avoid-social) (value yes))
    (symptom (name fear-social) (value yes))
    (symptom (name fear-humiliation) (value yes))
    =>
    (assert (generalized-anxiety-list (generalized-anxiety-names

I'm stuck here. How can I assert those symptoms inside the generalized-anxiety-list ?

UPDATED

I've created a new deftemplate named count-all to count all symptoms with both yes and no value. As long as the user input a new answer for the question, it will store the symptom's name in the count-all.

(deftemplate count-all
    (multislot names))

(defrule new-count-all
        (symptom (name ?name))
        =>
        (assert (count-all (names ?name))))
    
    (defrule add-to-count-all
        (symptom (name ?name))
        ?sl <- (count-all (names $?names&~:(member$ ?name ?names)))
        =>
        (modify ?sl (names ?names ?name)))

Solution

  • Create a deftemplate for generically representing the symptoms (or responses or whatever you want to call them):

             CLIPS (6.4 2/9/21)
    CLIPS> 
    (deftemplate symptom
       (slot name)
       (slot value))   
    CLIPS>  
    

    Adding a deftemplate and rules for collecting together all symptoms sharing a common value:

    CLIPS>    
    (deftemplate symptom-list
       (multislot names)
       (slot value))
    CLIPS>    
    (defrule new-symptom-list
       (symptom (name ?name)
                (value ?value))
       (not (symptom-list (value ?value)))
       =>
       (assert (symptom-list (names ?name) (value ?value))))
    CLIPS>    
    (defrule add-to-symptom-list
       (symptom (name ?name)
                (value ?value))
       ?sl <- (symptom-list (names $?names&~:(member$ ?name ?names)) 
                            (value ?value))
       =>
       (modify ?sl (names ?names ?name)))
    CLIPS> 
    

    Modify your existing rules to make use of the new symptom deftemplate:

    CLIPS>    
    (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)
    CLIPS> 
    (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))
    CLIPS> 
    (defrule start
        (declare (salience 10))
        =>
        (printout t crlf crlf)
        (printout t "Anxiety Diagnosis Expert System")
        (printout t crlf crlf)
        (assert (symptom (name have-anxiety)
                         (value (yes-or-no-p "Do you have an excessive anxiety and worry?: ")))))
    CLIPS> 
    (defrule f-3
        (symptom (name have-anxiety) (value yes))
        =>
        (assert (symptom (name heart_palpitation) (value (yes-or-no-p "Heart palpitation?: ")))))
    CLIPS> 
    (defrule f-4
        (symptom (name have-anxiety) (value yes))
        (symptom (name heart_palpitation) (value yes))
        =>
        (assert (symptom (name excess_sweating) (value (yes-or-no-p "Excessive sweating?: ")))))
    CLIPS> 
    (defrule f-5
        (symptom (name have-anxiety) (value yes))
        (symptom (name heart_palpitation) (value yes))
        =>
        (assert (symptom (name body_trembling) (value (yes-or-no-p "Trembling on some parts of body?: ")))))
    CLIPS>
    

    Now when you run the program, the symptom-list facts will have the collections of symptoms with the same value:

    CLIPS> (reset)
    CLIPS> (run)
    
    
    Anxiety Diagnosis Expert System
    
    Do you have an excessive anxiety and worry?: yes
    Heart palpitation?: yes
    Excessive sweating?: no
    Trembling on some parts of body?: yes
    CLIPS> (facts)
    f-1     (symptom (name have-anxiety) (value yes))
    f-2     (symptom-list (names have-anxiety heart_palpitation body_trembling) (value yes))
    f-3     (symptom (name heart_palpitation) (value yes))
    f-4     (symptom (name excess_sweating) (value no))
    f-5     (symptom-list (names excess_sweating) (value no))
    f-6     (symptom (name body_trembling) (value yes))
    For a total of 6 facts.
    CLIPS>
    

    You can now write rules where the actions or conditions retrieve the count of the symptoms with a similar value:

    CLIPS> 
    (defrule count-yes-symptoms
       (symptom-list (names $?names) (value yes))
       =>
       (println "Number of symptoms with value yes = " (length$ ?names)))
    CLIPS> (run)
    Number of symptoms with value yes = 3
    CLIPS>