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:

    CLIPS> (run)
    String? aaabba
    CLIPS> (reset)
    CLIPS> (run)
    String? aabbba
  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))
    CLIPS> (assert (fact_run 5))
    CLIPS> (run)
    CLIPS> (facts)
    f-0  (fact_run 5)
    f-1  (fact 0 120)