next up previous

4 Deffacts Construct

With the deffacts construct, a list of facts can be defined which are automatically asserted whenever the reset command is performed. Facts asserted through deffacts may be retracted or patternmatched like any other fact. The initial factlist, including any defined deffacts, is always reconstructed after a reset command.

Syntax

(deffacts <deffacts-name> [<comment>]
   <RHS-pattern>*)

Redefining a currently existing deffacts causes the previous deffacts with the same name to be removed even if the new definition has errors in it. There may be multiple deffacts constructs and any number of facts (either ordered or deftemplate) may be asserted into the initial factlist by each deffacts construct.

Dynamic expressions may be included in a fact by embedding the expression directly within the fact. All such expressions are evaluated when CLIPS is reset.

Example

(deffacts startup "Refrigerator Status"
   (refrigerator light on)
   (refrigerator door open)
   (refrigerator temp (get-temp)))

Upon startup and after a clear command, CLIPS automatically constructs the following deftemplate and deffacts.

(deftemplate initial-fact)
(deffacts initial-fact
   (initial-fact))

This deffacts provides a convenient method for starting the execution of a system ñ Rules that are given no conditional element are automatically given a pattern which matches the (initialfact) fact. The initialfact deffacts can be treated identically as any other deffacts defined by the user.




next up previous