5
Making a List As with other programming languages, CLIPS recognizes certain keywords. For example, if you want to put data in the fact-list, you can use the assert command. CLIPS> (assert (duck)) CLIPS> (facts) f-0 (initial-fact) f-1 (duck) For a total of 2 facts. CLIPS>

6
What happens if you try to put a second duck into the fact-list? Let's try it and see. Assert a new (duck), then issue a (facts) command as follows

7
Facts command The keyboard command to see facts is with the facts command. Enter (facts) in response to the CLIPS prompt and CLIPS will respond with a list of facts in the fact-list. Be sure to put parentheses around the command or CLIPS will not accept it. The result of the (facts) command in this example should be CLIPS> (facts) f-0 (initial-fact) f-1 (duck) For a total of 2 facts. CLIPS>

8
Clearing Up the Facts The (clear) command actually does more than just remove facts. Besides removing all the facts, (clear) also removes all the rules. CLIPS> (facts) f-0 (initial-fact) f-1 (duck) f-2 (quack) For a total of 3 facts. CLIPS> (clear) CLIPS>

10
Retract that Fact Removing facts from the fact-list is called retraction and is done with the retract command. To retract a fact, you must specify the fact- index. CLIPS> (retract 3) CLIPS>

11
You can also retract multiple facts at once, as shown by the following. CLIPS> (retract 1 3) CLIPS> (facts) f-0 (initial-fact) f-2 (animal-sound quack) For a total of 2 facts. You can just use (retract *) to retract all the facts, where the "*" indicates all.

16
CLIPS is said to be case-sensitive because it distinguishes between uppercase and lowercase letters. For example, assert the facts (duck) and (Duck) and then issue a (facts) command. You'll see that CLIPS allows you to assert (duck) and (Duck) as different facts because CLIPS is case-sensitive.

18
What if you want to include the double quotes in a field? The correct way to put double quotes in a fact is with the backslash, "\", as the following example shows. CLIPS> (clear) CLIPS> (assert (single-quote "duck")) CLIPS> (assert (double-quote "\"duck\"")) CLIPS> (facts) f-0 (initial-fact) f-1 (single-quote "duck") f-2 (double-quote ""duck"") For a total of 3 facts. CLIPS>

20
Making Good Rules To accomplish useful work, an expert system must have rules as well as facts. The pseudocode for a rule about duck sounds might be IF the animal is a duck THEN the sound made is quack CLIPS> (assert (animal-is duck)) CLIPS> (defrule duck (animal-is duck) => (assert (sound-is quack))) CLIPS>

22
Rule name Entering the same rule name, in this case "duck", will replace any existing rule with that name. That is, while there can be many rules in CLIPS, there can be only one rule which is named "duck". This is analogous to other programming languages in which only one procedure name can be used to uniquely identify a procedure.

23
The general syntax of a rule is shown following. (defrule rule_name "optional_comment" (pattern_1) ; Left-Hand Side (LHS) (pattern_2) ; of the rule consisting of elements. ; before the "=>". (pattern_N) => (action_1) ; Right-Hand Side (RHS) (action_2) ; of the rule consisting of elements. ; after the "=>". (action_M)) ; the last ")" balances the opening ; "(" to the left of "defrule". Be ; sure all your parentheses balance ; or you will get error messages

24
The part of the rule before the arrow is called the left-hand side (LHS) and the part of the rule after the arrow is called the right-hand side (RHS). If no patterns are specified

25
Before going on, let's save the duck rule with the save command so that you don't have to type it in again. Just enter a command such as (save "duck.clp")