CLIPS Exercises

Author: Jack L. Watkin

CPS 499-03: Emerging Languages, Spring 2017

  1. Build a state machine using CLIPS that accepts a language L consisting of strings in which the number of a's in the string is a multiple of three over an alphabet {a,b}. Use the following state machine:

    Examples:
    CLIPS> (run)
    String? aaabba
    Rejected
    
    CLIPS> (reset)
    CLIPS> (run)
    String? aabbba
    Accepted
    
  2. Rewrite the following factorial program in CLIPS so that only the fact with the final result of the factorial rule is stored in the fact list. Hint: retract can be used to remove facts from the fact list.

    (defrule factorial
       (fact_run ?x)
       =>
       (assert (fact ?x 1)))
    
    (defrule fact_helper
       (fact ?x ?y)
       (test (> ?x 0))
       =>
       (assert (fact (- ?x 1) (* ?x ?y))))
    
    (assert (fact_run 5))
    
    Examples:
    CLIPS> (assert (fact_run 5))
    CLIPS> (run)
    CLIPS> (facts)
    f-0  (fact_run 5)
    f-1  (fact 0 120)