;;; Variables and wild cards example ;;; ;;; Peter Cheng. Jan 2009. ;;; ;;; Instructions ;;; 1 - Load the deffacts and the first rule ;;; 2 - (reset) to load the facts into WM - look at them in the facts/WM window ;;; 3 - How many activations on the agenda and which fact is/are they associated with? ;;; 4 - Run the model, see what happens. ;;; 5 - (clear) CLIPS ;;; 6 - repeat steps 1-5 for each of the other rules ;;; Remember you can just select parts of the file and do 'load selection'. ;;; 7 - Add some more facts to the deffacts and write a new rule to put a new fact in WM with the last name. ;;; 8 - Write a new rule that will reverse the order of the first and last names of every one. (deffacts some-facts "various facts of the same type" (goal default) (name peter cheng) (name jane smith) (name barack obama) (name michelle obama)) ;;; example 1 (defrule one-particular-pattern-with-literal-symbols-in-LHS (goal default) (name barack obama) => (assert (president obama)) ) ;;; example 2 (defrule wild-card (goal default) (name ? obama) ; ?ft is the variable for a fact => (assert (there-is-someone-with-the-name-obama (gensym)))) ; (gensym) creates an arbitary symbol, so that each version of this fact will be different ;;; example 3 (defrule first-name-when-last-name-is-obama (goal default) (name ?first obama) ; ?first is a variable => (assert (first-name ?first)) ; put the symbol stored in ?first in this fact )