CLIPS - C Language Integrated Production System (Notes for version 3.1) Also has object oriented programming embedded in it. Facts are lists of values. A value is a symbol, number or string. A symbol begins with a letter; the remaining characters are letters, digits, underscores, dashes. (use \" to include " in a string.) ----- (assert ) adds fact. (facts) lists all facts in fact base and shows their number. (retract ...) retracts fact with number . (clear) removes all facts, rules. (deffacts ... ) defines a block of facts that can be used to initialize the system. (reset) adds defined facts plus (initial-fact) to fact base. (undeffacts ) undefines the named block of facts. (undeffacts initial-fact) removes (initial-fact) as default. Rules have a conditions => actions format. ----- (rules) lists the names of all rules currently loaded. (defrule "" ; comment is optional (declare (salience )) ; this line is optional ... => ... ) Salience is the priority level used to select which rule on the agenda to fire. Salience ranges from -10000 to 10000. Default value is 0. The expression giving the salience is usually a number, but it can be a function call that computes it dynamically. (agenda) displays rules ready for firing. (pprule ) displays named rule. (excise ) removes named rule. A condition has the form: (test ) (or ... ) ; Clips 6.0 only (|| ... ) ; Clips 3.1 only (and ... ) ; Clips 6.0 only (&& ... ) ; Clips 3.1 only (not ) <- In the <- case, is expected to match a single fact, to which the variable binds so that the fact can be removed with a (retract ) action. In this context, a variable has the form ?. Patterns are like facts but they can contain special symbols and expressions: Variables have the form ? or $?. ? binds to one value in the matching fact, $? binds to a sublist of values in the matching fact. Wildcards act like variables except that they don't actually bind. ? and $? are the wildcards, matching any single value or sublist of values, respectively. ~ matches anything except . | matches either value. & matches an element of a fact when it matches both values. Useful when one of of the values is a variable. Combinations are also possible, as in ?var2&~?var1. Tests can be applied immediately to an atom with the &: connective. Example: ?age&:(&& (> ?age 16) (<= ?age 65)) binds a number to ?age provided it is in the range 17 through 65. When a pattern appears in an assert command, it can contain a function call in the form =. The value of the function call will be used in place of this expression when the fact is formed. Actions are function calls (in lisp notation). Examples are: (assert ) (retract ...) (bind ) (printout ...) (fprintout ...) crlf is a constant. t is the logical name of the terminal. (call (open "" )) modes are "r", "w", "r+" (read and write), "a" (append). (call (close )) (if then ... else ...) ; else branch is optional (while do ...) ; avoid this if you can Some functions should only appear embedded inside other functions or patterns: arithmetic functions, e.g., (+ ...), (- ...), (* ...), (/ ...), (abs ...), (min ...), (max ...), (** ...). ; exponentiation numerical comparisons, e.g., >, >=, =, !=, <. <=. other comparisons: eq, neq. boolean functions: !, not, &&, and, ||, or. (read ) (omitting logical name makes it default to t.) (numberp ) Is the value a number? (stringp ) Is the value not a number? (evenp ) Is the value even? (oddp ) Is the value odd? Note: the atom EOF is returned by read at end of file Your .CLP file can contain lisp-like comments: ; the rest of the line after a semi-colon is a comment. (reset) initializes loaded system. (run) runs the system. (run ) runs the system for more rule firings. (exit) terminates Clips. (load "") loads a file of deffacts and defrules. (.clp is the conventional extension.) If you want to, you can type facts and rules interactively into CLIPS and save the system with the (save "") command, but this is not my style. Debugging commands: (watch facts) displays facts as they are asserted and retracted (watch rules) displays rule firings (watch activations) displays activations (ready for firing) and deactivations of rules (unwatch ) where is the symbol facts, rules, or activations, turns off watch operation. ==========WHERE TO GET CLIPS============== To get CLIPS 3.1 to run on your Windows PC, log onto one of the composers, go to directory ~chester and download clips31.zip. Unzip this file. The file clips.exe is the executable interpreter for CLIPS 3.1. The clips31.zip file also contains examples of clips programs, documentation and source code, though the source code has some mistakes in it and is not satisfactorily compilable with gcc. WARNING: The file clips31.zip also contains a file called roff4st.exe. DO NOT RUN THIS FILE. It will mess up your computer and crash it. Version 6.0 of CLIPS is available in my directory on Strauss; just run ~chester/clips. The documenation that appears in clips31.zip has been placed in the directory ~chester/clipsdocs so that CLIPS 6.0 users can read them without unzipping clisp31.zip. In addition, the example CLIPS programs have been converted to run in CLIPS 6.0 and placed in my directory. To see a list of these examples, type ls *x.clp. -------------------------------------------- Differences between clips 6.0 and clips 3.1. -------------------------------------------- 1. The function printout in clips 6.0 is the same as fprintout in clips 3.1. 2. The functions or and and work only in clips 6.0; the functions || and && work only in clips 3.1. 3. Clips 6.0 uses not in place of !. (!= x y) must be (not (= x y)). The function not works in clips 3.1 as well. 4. The word object has special meaning in clips 6.0; don't use it. 5. The structure of facts (a list of atoms) is interpreted slightly differently in clips 6.0. As a consequence, the first element in a pattern must be a symbol atom, not a variable; think of it as a predicate name that must always be explicitly specified in patterns. 6. Clips 6.0 has a help command. The clips executable file consults the file clips.hlp for the help information it displays. 7. The function pprule in clips 3.1 is called ppdefrule in clips 6.0. 8. The function excise in clips 3.1 is called undefrule in clips 6.0. I have put the clips reference file and the .man files (a user guide) that are bundled in clips31.zip in directory ~chester/clipsdocs so that clips 6.0 users can read them without unzipping clips31.zip.