
Reference Manual
Volume I
Basic Programming Guide
Version 6.24
June 15th 2006
CLIPS Basic
Programming Guide
Version 6.24 June 15th 2006
CONTENTS
License Information....................................................................................................................... i
Preface............................................................................................................................................ iii
Acknowledgements...................................................................................................................... vii
Section 1 ‑ Introduction................................................................................................................ 1
Section 2 ‑ CLIPS Overview......................................................................................................... 3
2.1 Interacting with CLIPS........................................................................................................ 3
2.1.1 Top Level Commands................................................................................................. 3
2.1.2 Automated Command Entry and Loading................................................................... 4
2.1.3 Integration with Other Languages............................................................................... 5
2.2 Reference Manual Syntax.................................................................................................... 5
2.3 Basic Programming Elements.............................................................................................. 6
2.3.1 Data Types.................................................................................................................. 6
2.3.2 Functions.................................................................................................................... 9
2.3.3 Constructs................................................................................................................. 10
2.4 Data Abstraction................................................................................................................ 10
2.4.1 Facts.......................................................................................................................... 10
2.4.1.1 Ordered Facts................................................................................................... 11
2.4.1.2 Non‑ordered Facts........................................................................................... 12
2.4.1.3 Initial Facts....................................................................................................... 13
2.4.2 Objects...................................................................................................................... 13
2.4.2.1 Initial Objects................................................................................................... 14
2.4.3 Global Variables....................................................................................................... 14
2.5 Knowledge Representation................................................................................................ 15
2.5.1 Heuristic Knowledge – Rules................................................................................... 15
2.5.2 Procedural Knowledge.............................................................................................. 16
2.5.2.1 Deffunctions.................................................................................................... 16
2.5.2.2 Generic Functions............................................................................................ 16
2.5.2.3 Object Message‑Passing.................................................................................. 16
2.5.2.4 Defmodules...................................................................................................... 17
2.6 CLIPS Object‑Oriented Language..................................................................................... 17
2.6.1 COOL Deviations from a Pure OOP Paradigm........................................................ 17
2.6.2 Primary OOP Features.............................................................................................. 18
2.6.3 Instance‑set Queries and Distributed Actions........................................................... 18
Section 3 ‑ Deftemplate Construct............................................................................................. 19
3.1 Slot Default Values............................................................................................................ 20
3.2 Slot Default Constraints for Pattern‑Matching................................................................... 20
3.3 Slot Value Constraint Attributes........................................................................................ 21
3.4 Implied Deftemplates......................................................................................................... 21
Section 4 ‑ Deffacts Construct.................................................................................................... 23
Section 5 ‑ Defrule Construct..................................................................................................... 25
5.1 Defining Rules................................................................................................................... 25
5.2 Basic Cycle Of Rule Execution.......................................................................................... 26
5.3 Conflict Resolution Strategies............................................................................................ 27
5.3.1 Depth Strategy.......................................................................................................... 27
5.3.2 Breadth Strategy........................................................................................................ 27
5.3.3 Simplicity Strategy.................................................................................................... 27
5.3.4 Complexity Strategy.................................................................................................. 28
5.3.5 LEX Strategy............................................................................................................ 28
5.3.6 MEA Strategy........................................................................................................... 29
5.3.7 Random Strategy....................................................................................................... 29
5.4 LHS Syntax....................................................................................................................... 31
5.4.1 Pattern Conditional Element...................................................................................... 31
5.4.1.1 Literal Constraints............................................................................................ 32
5.4.1.2 Wildcards Single‑ and Multifield..................................................................... 34
5.4.1.3 Variables Single‑ and Multifield...................................................................... 36
5.4.1.4 Connective Constraints.................................................................................... 38
5.4.1.5 Predicate Constraints........................................................................................ 41
5.4.1.6 Return Value Constraints................................................................................. 43
5.4.1.7 Pattern‑Matching with Object Patterns............................................................. 44
5.4.1.8 Pattern‑Addresses............................................................................................ 47
5.4.2 Test Conditional Element.......................................................................................... 47
5.4.3 Or Conditional Element............................................................................................. 49
5.4.4 And Conditional Element.......................................................................................... 50
5.4.5 Not Conditional Element........................................................................................... 51
5.4.6 Exists Conditional Element....................................................................................... 52
5.4.7 Forall Conditional Element........................................................................................ 54
5.4.8 Logical Conditional Element..................................................................................... 56
5.4.9 Automatic Addition and Reordering of LHS CEs..................................................... 59
5.4.9.1 Rules Without Any LHS Pattern CEs.............................................................. 59
5.4.9.2 Test and Not CEs as the First CE of an And CE.............................................. 59
5.4.9.3 Test CEs Following Not CEs........................................................................... 60
5.4.9.4 Or CEs Following Not CEs............................................................................. 61
5.4.9.5 Notes About Pattern Addition and Reordering................................................ 61
5.4.10 Declaring Rule Properties....................................................................................... 61
5.4.10.1 The Salience Rule Property............................................................................ 62
5.4.10.2 The Auto‑Focus Rule Property...................................................................... 63
Section 6 ‑ Defglobal Construct.................................................................................................. 65
Section 7 ‑ Deffunction Construct.............................................................................................. 71
Section 8 ‑ Generic Functions..................................................................................................... 73
8.1 Note on the Use of the Term Method................................................................................. 73
8.2 Performance Penalty of Generic Functions........................................................................ 74
8.3 Order Dependence of Generic Function Definitions.......................................................... 74
8.4 Defining a New Generic Function..................................................................................... 74
8.4.1 Generic Function Headers......................................................................................... 75
8.4.2 Method Indices......................................................................................................... 75
8.4.3 Method Parameter Restrictions................................................................................. 76
8.4.4 Method Wildcard Parameter...................................................................................... 77
8.5 Generic Dispatch................................................................................................................ 79
8.5.1 Applicability of Methods Summary.......................................................................... 79
8.5.2 Method Precedence................................................................................................... 80
8.5.3 Shadowed Methods.................................................................................................. 83
8.5.4 Method Execution Errors.......................................................................................... 83
8.5.5 Generic Function Return Value................................................................................. 83
Section 9 ‑ CLIPS Object Oriented Language (COOL)........................................................... 85
9.1 Background........................................................................................................................ 85
9.2 Predefined System Classes................................................................................................ 85
9.3 Defclass Construct............................................................................................................. 86
9.3.1 Multiple Inheritance.................................................................................................. 87
9.3.1.1 Multiple Inheritance Rules............................................................................... 88
9.3.2 Class Specifiers......................................................................................................... 90
9.3.2.1 Abstract and Concrete Classes......................................................................... 90
9.3.2.2 Reactive and Non‑Reactive Classes................................................................. 90
9.3.3 Slots.......................................................................................................................... 90
9.3.3.1 Slot Field Type................................................................................................. 91
9.3.3.2 Default Value Facet.......................................................................................... 91
9.3.3.3 Storage Facet.................................................................................................... 92
9.3.3.4 Access Facet.................................................................................................... 93
9.3.3.5 Inheritance Propagation Facet.......................................................................... 94
9.3.3.6 Source Facet..................................................................................................... 95
9.3.3.7 Pattern‑Match Reactivity Facet......................................................................... 96
9.3.3.8 Visibility Facet................................................................................................. 97
9.3.3.9 Create‑Accessor Facet...................................................................................... 98
9.3.3.10 Override‑Message Facet................................................................................ 99
9.3.3.11 Constraint Facets............................................................................................ 99
9.3.4 Message‑handler Documentation............................................................................ 100
9.4 Defmessage‑handler Construct........................................................................................ 101
9.4.1 Message‑handler Parameters................................................................................... 103
9.4.1.1 Active Instance Parameter.............................................................................. 103
9.4.2 Message‑handler Actions........................................................................................ 104
9.4.3 Daemons................................................................................................................. 106
9.4.4 Predefined System Message‑handlers..................................................................... 106
9.4.4.1 Instance Initialization...................................................................................... 106
9.4.4.2 Instance Deletion............................................................................................ 107
9.4.4.3 Instance Display............................................................................................. 108
9.4.4.4 Directly Modifying an Instance...................................................................... 108
9.4.4.5 Modifying an Instance using Messages......................................................... 109
9.4.4.6 Directly Duplicating an Instance.................................................................... 109
9.4.4.7 Duplicating an Instance using Messages........................................................ 110
9.4.4.8 Instance Creation............................................................................................ 110
9.5 Message Dispatch............................................................................................................ 110
9.5.1 Applicability of Message‑handlers.......................................................................... 111
9.5.2 Message‑handler Precedence.................................................................................. 111
9.5.3 Shadowed Message‑handlers.................................................................................. 112
9.5.4 Message Execution Errors...................................................................................... 112
9.5.5 Message Return Value............................................................................................ 113
9.6 Manipulating Instances.................................................................................................... 113
9.6.1 Creating Instances................................................................................................... 113
9.6.1.1 Definstances Construct.................................................................................. 115
9.6.2 Reinitializing Existing Instances..............................................................................