Download CLIPS User's Guide
Transcript
— 59 — (default 80))) CLIPS> (defrule happy_relationship (prospect (name $?name) (assets ?net_worth) (age ?months)) => (printout t "Prospect: " ?name crlf ; Note: not ?name ?net_worth crlf ?months " months old" crlf)) CLIPS> (deffacts duck-bachelor (prospect (name Dopey Wonderful) (assets rich) (age 99))) CLIPS> (reset) CLIPS> (run) Prospect: (Dopey Wonderful) rich 99 months old CLIPS> In the output, the parentheses around Dopey's name are put in by CLIPS to indicate that this is a multislot value. If you compare the output from this multislot version to the single-slot version, you'll see that the double quotes around "Dopey Wonderful" are gone. The name slot is not a string in the multislot version, so CLIPS treats the name as two independent fields, Dopey and Wonderful. What's in a Name Deftemplate greatly simplifies accessing a specific field in a pattern because the desired field can be identified by its slot name. The modify action can be used to retract and assert a new fact in one action by specifying one or more template slots to be modified. As an example, consider the following rules which show what happens when duck-bachelor Dopey Wonderful loses all his fish buying Donald Duck posters and banana fishsplits for his new duckette, Dixie. CLIPS> (undefrule *) CLIPS> (defrule make-bad-buys ?prospect <- (prospect (name $?name) (assets rich) (age ?months)) => (printout t "Prospect: " ?name crlf ; Note: not ?name