Reference Manual
Volume I
Basic Programming Guide
Version 6.30
March 17th 2015
CLIPS Reference Manual
CLIPS Basic Programming Guide
Version 6.30 March 17th 2015
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 Programming 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 ................................................................................................................ 11
2.4.1 Facts .......................................................................................................................... 11
2.4.2 Objects ...................................................................................................................... 13
2.4.3 Global Variables ....................................................................................................... 15
2.5 Knowledge Representation ................................................................................................ 15
2.5.1 Heuristic Knowledge – Rules ................................................................................... 15
2.5.2 Procedural Knowledge ............................................................................................. 16
2.6 CLIPS Object-Oriented Language .................................................................................... 18
2.6.1 COOL Deviations from a Pure OOP Paradigm ........................................................ 18
2.6.2 Primary OOP Features .............................................................................................. 18
2.6.3 Instance-set Queries and Distributed Actions .......................................................... 19
Section 3: Deftemplate Construct ............................................................................................. 21
3.1 Slot Default Values............................................................................................................ 22
3.2 Slot Default Constraints for Pattern-Matching .................................................................. 23
3.3 Slot Value Constraint Attributes ....................................................................................... 23
3.4 Implied Deftemplates ........................................................................................................ 23
Section 4: Deffacts Construct .................................................................................................... 25
Section 5: Defrule Construct ..................................................................................................... 27
CLIPS Basic Programming Guide
i
CLIPS Reference Manual
5.1 Defining Rules ................................................................................................................... 27
5.2 Basic Cycle Of Rule Execution ......................................................................................... 28
5.3 Conflict Resolution Strategies ........................................................................................... 29
5.3.1 Depth Strategy .......................................................................................................... 29
5.3.2 Breadth Strategy ....................................................................................................... 29
5.3.3 Simplicity Strategy ................................................................................................... 29
5.3.4 Complexity Strategy ................................................................................................. 30
5.3.5 LEX Strategy ............................................................................................................ 30
5.3.6 MEA Strategy ........................................................................................................... 31
5.3.7 Random Strategy ...................................................................................................... 32
5.4 LHS Syntax ....................................................................................................................... 33
5.4.1 Pattern Conditional Element..................................................................................... 34
5.4.2 Test Conditional Element ......................................................................................... 51
5.4.3 Or Conditional Element ............................................................................................ 52
5.4.4 And Conditional Element ......................................................................................... 53
5.4.5 Not Conditional Element .......................................................................................... 54
5.4.6 Exists Conditional Element ...................................................................................... 55
5.4.7 Forall Conditional Element ...................................................................................... 56
5.4.8 Logical Conditional Element .................................................................................... 58
5.4.9 Automatic Replacement of LHS CEs ....................................................................... 61
5.4.10 Declaring Rule Properties....................................................................................... 62
Section 6: Defglobal Construct .................................................................................................. 65
Section 7: Deffunction Construct .............................................................................................. 71
Section 8: Generic Functions ..................................................................................................... 75
8.1 Note on the Use of the Term Method ................................................................................ 75
8.2 Performance Penalty of Generic Functions ....................................................................... 76
8.3 Order Dependence of Generic Function Definitions ......................................................... 76
8.4 Defining a New Generic Function ..................................................................................... 76
8.4.1 Generic Function Headers ........................................................................................ 77
8.4.2 Method Indices ......................................................................................................... 77
8.4.3 Method Parameter Restrictions ................................................................................ 78
8.4.4 Method Wildcard Parameter..................................................................................... 79
8.5 Generic Dispatch ............................................................................................................... 81
8.5.1 Applicability of Methods Summary ......................................................................... 82
8.5.2 Method Precedence .................................................................................................. 84
8.5.3 Shadowed Methods .................................................................................................. 86
8.5.4 Method Execution Errors ......................................................................................... 86
8.5.5 Generic Function Return Value ................................................................................ 87
Section 9: CLIPS Object Oriented Language .......................................................................... 89
9.1 Background........................................................................................................................ 89
ii
Table of Contents
CLIPS Reference Manual
9.2 Predefined System Classes ................................................................................................ 89
9.3 Defclass Construct ............................................................................................................. 91
9.3.1 Multiple Inheritance ................................................................................................. 92
9.3.2 Class Specifiers ........................................................................................................ 95
9.3.3 Slots .......................................................................................................................... 95
9.3.4 Message-handler Documentation ........................................................................... 105
9.4 Defmessage-handler Construct ........................................................................................ 106
9.4.1 Message-handler Parameters .................................................................................. 108
9.4.2 Message-handler Actions ....................................................................................... 109
9.4.3 Daemons ................................................................................................................. 111
9.4.4 Predefined System Message-handlers .................................................................... 112
9.5 Message Dispatch ............................................................................................................ 116
9.5.1 Applicability of Message-handlers ......................................................................... 118
9.5.2 Message-handler Precedence.................................................................................. 118
9.5.3 Shadowed Message-handlers.................................................................................. 118
9.5.4 Message Execution Errors ...................................................................................... 119
9.5.5 Message Return Value ............................................................................................ 120
9.6 Manipulating Instances .................................................................................................... 120
9.6.1 Creating Instances .................................................................................................. 120
9.6.2 Reinitializing Existing Instances ............................................................................ 124
9.6.3 Reading Slots .......................................................................................................... 125
9.6.4 Setting Slots ............................................................................................................ 125
9.6.5 Deleting Instances .................................................................................................. 126
9.6.6 Delayed Pattern-Matching When Manipulating Instances ..................................... 126
9.6.7 Modifying Instances ............................................................................................... 127
9.6.8 Duplicating Instances ............................................................................................. 129
9.7 Instance-set Queries and Distributed Actions ................................................................. 132
9.7.1 Instance-set Definition............................................................................................ 135
9.7.2 Instance-set Determination ..................................................................................... 135
9.7.3 Query Definition ..................................................................................................... 137
9.7.4 Distributed Action Definition ................................................................................. 137
9.7.5 Scope in Instance-set Query Functions .................................................................. 138
9.7.6 Errors during Instance-set Query Functions ........................................................... 139
9.7.7 Halting and Returning Values from Query Functions ............................................ 139
9.7.8 Instance-set Query Functions ................................................................................. 139
Section 10: Defmodule Construct............................................................................................ 145
10.1 Defining Modules .......................................................................................................... 145
10.2 Specifying a Construct’s Module .................................................................................. 146
10.3 Specifying Modules ....................................................................................................... 147
10.4 Importing and Exporting Constructs ............................................................................. 147
10.4.1 Exporting Constructs ............................................................................................ 148
10.4.2 Importing Constructs ............................................................................................ 149
CLIPS Basic Programming Guide
iii
CLIPS Reference Manual
10.5 Importing and Exporting Facts and Instances ............................................................... 150
10.5.1 Specifying Instance-Names .................................................................................. 150
10.6 Modules and Rule Execution......................................................................................... 151
Section 11: Constraint Attributes ........................................................................................... 153
11.1 Type Attribute ............................................................................................................... 153
11.2 Allowed Constant Attributes ......................................................................................... 154
11.3 Range Attribute ............................................................................................................. 155
11.4 Cardinality Attribute ...................................................................................................... 155
11.5 Deriving a Default Value From Constraints .................................................................. 156
11.6 Constraint Violation Examples...................................................................................... 157
Section 12: Actions And Functions ......................................................................................... 159
12.1 Predicate Functions ....................................................................................................... 159
12.1.1 Testing For Numbers ............................................................................................ 159
12.1.2 Testing For Floats ................................................................................................. 159
12.1.3 Testing For Integers .............................................................................................. 159
12.1.4 Testing For Strings Or Symbols ........................................................................... 160
12.1.5 Testing For Strings ............................................................................................... 160
12.1.6 Testing For Symbols............................................................................................. 160
12.1.7 Testing For Even Numbers ................................................................................... 160
12.1.8 Testing For Odd Numbers .................................................................................... 161
12.1.9 Testing For Multifield Values .............................................................................. 161
12.1.10 Testing For External-Addresses ......................................................................... 161
12.1.11 Comparing for Equality ...................................................................................... 161
12.1.12 Comparing for Inequality ................................................................................... 162
12.1.13 Comparing Numbers for Equality ...................................................................... 162
12.1.14 Comparing Numbers for Inequality.................................................................... 163
12.1.15 Greater Than Comparison .................................................................................. 163
12.1.16 Greater Than or Equal Comparison .................................................................... 164
12.1.17 Less Than Comparison ....................................................................................... 164
12.1.18 Less Than or Equal Comparison ........................................................................ 165
12.1.19 Boolean And ....................................................................................................... 165
12.1.20 Boolean Or.......................................................................................................... 165
12.1.21 Boolean Not ........................................................................................................ 166
12.2 Multifield Functions ...................................................................................................... 166
12.2.1 Creating Multifield Values ................................................................................... 166
12.2.2 Specifying an Element .......................................................................................... 166
12.2.3 Finding an Element............................................................................................... 167
12.2.4 Comparing Multifield Values ............................................................................... 167
12.2.5 Deletion of Fields in Multifield Values ................................................................ 168
12.2.6 Creating Multifield Values from Strings. ............................................................. 168
12.2.7 Creating Strings from Multifield Values .............................................................. 169
iv
Table of Contents
CLIPS Reference Manual
12.2.8 Extracting a Sub-sequence from a Multifield Value ............................................ 169
12.2.9 Replacing Fields within a Multifield Value ......................................................... 170
12.2.10 Inserting Fields within a Multifield Value ......................................................... 170
12.2.11 Getting the First Field from a Multifield Value ................................................. 171
12.2.12 Getting All but the First Field from a Multifield Value ..................................... 171
12.2.13 Determining the Number of Fields in a Multifield Value .................................. 172
12.2.14 Deleting Specific Values within a Multifield Value .......................................... 172
12.2.15 Replacing Specific Values within a Multifield Value ........................................ 172
12.3 String Functions............................................................................................................. 173
12.3.1 String Concatenation ............................................................................................ 173
12.3.2 Symbol Concatenation.......................................................................................... 173
12.3.3 Taking a String Apart ........................................................................................... 174
12.3.4 Searching a String................................................................................................. 174
12.3.5 Evaluating a Function within a String .................................................................. 175
12.3.6 Evaluating a Construct within a String ................................................................. 175
12.3.7 Converting a String to Uppercase......................................................................... 176
12.3.8 Converting a String to Lowercase ........................................................................ 176
12.3.9 Comparing Two Strings ....................................................................................... 176
12.3.10 Determining the Length of a String .................................................................... 177
12.3.11 Checking the Syntax of a Construct or Function Call within a String ............... 177
12.3.12 Converting a String to a Field ............................................................................ 178
12.4 The CLIPS I/O System .................................................................................................. 178
12.4.1 Logical Names ...................................................................................................... 179
12.4.2 Common I/O Functions ........................................................................................ 179
12.5 Math Functions .............................................................................................................. 189
12.5.1 Standard Math Functions ...................................................................................... 189
12.5.2 Extended Math Functions ..................................................................................... 194
12.6 Procedural Functions ..................................................................................................... 199
12.6.1 Binding Variables ................................................................................................. 199
12.6.2 If...then...else Function ......................................................................................... 200
12.6.3 While .................................................................................................................... 201
12.6.4 Loop-for-count ..................................................................................................... 202
12.6.5 Progn..................................................................................................................... 203
12.6.6 Progn$................................................................................................................... 203
12.6.7 Return ................................................................................................................... 204
12.6.8 Break..................................................................................................................... 204
12.6.9 Switch ................................................................................................................... 205
12.6.10 Foreach ............................................................................................................... 206
12.7 Miscellaneous Functions ............................................................................................... 207
12.7.1 Gensym ................................................................................................................. 207
12.7.2 Gensym* ............................................................................................................... 207
12.7.3 Setgen ................................................................................................................... 208
12.7.4 Random................................................................................................................. 208
CLIPS Basic Programming Guide
v
CLIPS Reference Manual
12.7.5 Seed ...................................................................................................................... 209
12.7.6 Time ...................................................................................................................... 209
12.7.7 Number of Fields or Characters in a Data Object ................................................ 209
12.7.8 Determining the Restrictions for a Function ........................................................ 210
12.7.9 Sorting a List of Values ........................................................................................ 210
12.7.10 Calling a Function .............................................................................................. 211
12.7.11 Timing Functions and Commands...................................................................... 211
12.7.12 Determining the Operating System .................................................................... 211
12.8 Deftemplate Functions................................................................................................... 212
12.8.1 Determining the Module in which a Deftemplate is Defined............................... 212
12.8.2 Getting the Allowed Values for a Deftemplate Slot ............................................. 212
12.8.3 Getting the Cardinality for a Deftemplate Slot..................................................... 212
12.8.4 Testing whether a Deftemplate Slot has a Default ............................................... 213
12.8.5 Getting the Default Value for a Deftemplate Slot ................................................ 214
12.8.6 Deftemplate Slot Existence .................................................................................. 214
12.8.7 Testing whether a Deftemplate Slot is a Multifield Slot ...................................... 215
12.8.8 Determining the Slot Names Associated with a Deftemplate .............................. 215
12.8.9 Getting the Numeric Range for a Deftemplate Slot ............................................. 215
12.8.10 Testing whether a Deftemplate Slot is a Single-Field Slot................................. 216
12.8.11 Getting the Primitive Types for a Deftemplate Slot ........................................... 216
12.8.12 Getting the List of Deftemplates ........................................................................ 217
12.9 Fact Functions ............................................................................................................... 217
12.9.1 Creating New Facts .............................................................................................. 217
12.9.2 Removing Facts from the Fact-list ....................................................................... 218
12.9.3 Modifying Template Facts ................................................................................... 219
12.9.4 Duplicating Template Facts .................................................................................. 220
12.9.5 Asserting a String ................................................................................................. 220
12.9.6 Getting the Fact-Index of a Fact-address.............................................................. 221
12.9.7 Determining If a Fact Exists ................................................................................. 222
12.9.8 Determining the Deftemplate (Relation) Name Associated with a Fact .............. 222
12.9.9 Determining the Slot Names Associated with a Fact ........................................... 222
12.9.10 Retrieving the Slot Value of a Fact .................................................................... 223
12.9.11 Retrieving the Fact-List ...................................................................................... 224
12.9.12 Fact-set Queries and Distributed Actions ........................................................... 224
12.10 Deffacts Functions ....................................................................................................... 234
12.10.1 Getting the List of Deffacts ................................................................................ 234
12.10.2 Determining the Module in which a Deffacts is Defined ................................... 234
12.11 Defrule Functions ........................................................................................................ 235
12.11.1 Getting the List of Defrules ................................................................................ 235
12.11.2 Determining the Module in which a Defrule is Defined .................................... 235
12.12 Agenda Functions ........................................................................................................ 235
12.12.1 Getting the Current Focus .................................................................................. 235
12.12.2 Getting the Focus Stack ...................................................................................... 236
vi
Table of Contents
CLIPS Reference Manual
12.12.3 Removing the Current Focus from the Focus Stack ........................................... 236
12.13 Defglobal Functions .................................................................................................... 237
12.13.1 Getting the List of Defglobals ............................................................................ 237
12.13.2 Determining the Module in which a Defglobal is Defined ................................ 238
12.14 Deffunction Functions ................................................................................................. 238
12.14.1 Getting the List of Deffunctions ......................................................................... 238
12.14.2 Determining the Module in which a Deffunction is Defined ............................. 238
12.15 Generic Function Functions ........................................................................................ 238
12.15.1 Getting the List of Defgenerics .......................................................................... 239
12.15.2 Determining the Module in which a Generic Function is Defined .................... 239
12.15.3 Getting the List of Defmethods .......................................................................... 239
12.15.4 Type Determination ............................................................................................ 240
12.15.5 Existence of Shadowed Methods........................................................................ 240
12.15.6 Calling Shadowed Methods ................................................................................ 240
12.15.7 Calling Shadowed Methods with Overrides ....................................................... 241
12.15.8 Calling a Specific Method .................................................................................. 242
12.15.9 Getting the Restrictions of Defmethods ............................................................. 243
12.16 CLIPS Object-Oriented Language (COOL) Functions ............................................... 244
12.16.1 Class Functions ................................................................................................... 244
12.16.2 Message-handler Functions ................................................................................ 254
12.16.3 Definstances Functions ....................................................................................... 256
12.16.4 Instance Manipulation Functions and Actions ................................................... 256
12.17 Defmodule Functions .................................................................................................. 263
12.17.1 Getting the List of Defmodules .......................................................................... 263
12.17.2 Setting the Current Module ................................................................................ 263
12.17.3 Getting the Current Module................................................................................ 263
12.18 Sequence Expansion .................................................................................................... 264
12.18.1 Sequence Expansion and Rules .......................................................................... 265
12.18.2 Multifield Expansion Function ........................................................................... 266
12.18.3 Setting The Sequence Operator Recognition Behavior ...................................... 266
12.18.4 Getting The Sequence Operator Recognition Behavior ..................................... 267
12.18.5 Sequence Operator Caveat ................................................................................. 267
Section 13: Commands ............................................................................................................. 269
13.1 Environment Commands ............................................................................................... 269
13.1.1 Loading Constructs From A File .......................................................................... 269
13.1.2 Loading Constructs From A File without Progress Information .......................... 269
13.1.3 Saving All Constructs To A File .......................................................................... 270
13.1.4 Loading a Binary Image ....................................................................................... 270
13.1.5 Saving a Binary Image ......................................................................................... 270
13.1.6 Clearing CLIPS .................................................................................................... 271
13.1.7 Exiting CLIPS ...................................................................................................... 271
13.1.8 Resetting CLIPS ................................................................................................... 271
CLIPS Basic Programming Guide
vii
CLIPS Reference Manual
13.1.9 Executing Commands From a File ....................................................................... 272
13.1.10 Executing Commands From a File Without Replacing Standard Input ............. 272
13.1.11 Determining CLIPS Compilation Options ......................................................... 273
13.1.12 Calling the Operating System ............................................................................. 273
13.1.13 Setting The Auto-Float Dividend Behavior ....................................................... 273
13.1.14 Getting The Auto-Float Dividend Behavior ....................................................... 274
13.1.15 Setting the Dynamic Constraint Checking Behavior.......................................... 274
13.1.16 Getting the Dynamic Constraint Checking Behavior ......................................... 274
13.1.17 Setting the Static Constraint Checking Behavior ............................................... 274
13.1.18 Getting the Static Constraint Checking Behavior .............................................. 275
13.1.19 Finding Symbols ................................................................................................. 275
13.2 Debugging Commands .................................................................................................. 275
13.2.1 Generating Trace Files ......................................................................................... 275
13.2.2 Closing Trace Files ............................................................................................... 276
13.2.3 Enabling Watch Items .......................................................................................... 276
13.2.4 Disabling Watch Items ......................................................................................... 278
13.2.5 Viewing the Current State of Watch Items........................................................... 278
13.3 Deftemplate Commands ................................................................................................ 279
13.3.1 Displaying the Text of a Deftemplate .................................................................. 279
13.3.2 Displaying the List of Deftemplates ..................................................................... 279
13.3.3 Deleting a Deftemplate ......................................................................................... 279
13.4 Fact Commands ............................................................................................................. 280
13.4.1 Displaying the Fact-List ....................................................................................... 280
13.4.2 Loading Facts From a File .................................................................................... 280
13.4.3 Saving The Fact-List To A File ............................................................................ 280
13.4.4 Setting the Duplication Behavior of Facts............................................................ 281
13.4.5 Getting the Duplication Behavior of Facts ........................................................... 282
13.4.6 Displaying a Single Fact ....................................................................................... 282
13.5 Deffacts Commands ...................................................................................................... 283
13.5.1 Displaying the Text of a Deffacts ......................................................................... 283
13.5.2 Displaying the List of Deffacts............................................................................. 283
13.5.3 Deleting a Deffacts ............................................................................................... 283
13.6 Defrule Commands ........................................................................................................ 283
13.6.1 Displaying the Text of a Rule ............................................................................... 284
13.6.2 Displaying the List of Rules ................................................................................. 284
13.6.3 Deleting a Defrule ................................................................................................ 284
13.6.4 Displaying Matches for a Rule ............................................................................. 284
13.6.5 Setting a Breakpoint for a Rule ............................................................................ 287
13.6.6 Removing a Breakpoint for a Rule ....................................................................... 287
13.6.7 Displaying Rule Breakpoints ................................................................................ 288
13.6.8 Refreshing a Rule ................................................................................................. 288
13.6.9 Setting the Incremental Reset Behavior ............................................................... 288
13.6.10 Getting the Incremental Reset Behavior............................................................. 288
viii
Table of Contents
CLIPS Reference Manual
13.6.11 Determining the Logical Dependencies of a Pattern Entity ............................... 289
13.6.12 Determining the Logical Dependents of a Pattern Entity ................................... 289
13.7 Agenda Commands ....................................................................................................... 289
13.7.1 Displaying the Agenda ......................................................................................... 290
13.7.2 Running CLIPS .................................................................................................... 290
13.7.3 Focusing on a Group of Rules .............................................................................. 290
13.7.4 Stopping Rule Execution ...................................................................................... 291
13.7.5 Setting The Current Conflict Resolution Strategy................................................ 291
13.7.6 Getting The Current Conflict Resolution Strategy ............................................... 291
13.7.7 Listing the Module Names on the Focus Stack .................................................... 291
13.7.8 Removing all Module Names from the Focus Stack ............................................ 292
13.7.9 Setting the Salience Evaluation Behavior ............................................................ 292
13.7.10 Getting the Salience Evaluation Behavior .......................................................... 292
13.7.11 Refreshing the Salience Value of Rules on the Agenda ..................................... 292
13.8 Defglobal Commands .................................................................................................... 293
13.8.1 Displaying the Text of a Defglobal ...................................................................... 293
13.8.2 Displaying the List of Defglobals......................................................................... 293
13.8.3 Deleting a Defglobal............................................................................................. 293
13.8.4 Displaying the Values of Global Variables .......................................................... 294
13.8.5 Setting the Reset Behavior of Global Variables ................................................... 294
13.8.6 Getting the Reset Behavior of Global Variables .................................................. 294
13.9 Deffunction Commands................................................................................................. 294
13.9.1 Displaying the Text of a Deffunction ................................................................... 295
13.9.2 Displaying the List of Deffunctions ..................................................................... 295
13.9.3 Deleting a Deffunction ......................................................................................... 295
13.10 Generic Function Commands ...................................................................................... 295
13.10.1 Displaying the Text of a Generic Function Header ............................................ 295
13.10.2 Displaying the Text of a Generic Function Method ........................................... 296
13.10.3 Displaying the List of Generic Functions ........................................................... 296
13.10.4 Displaying the List of Methods for a Generic Function ..................................... 296
13.10.5 Deleting a Generic Function ............................................................................... 296
13.10.6 Deleting a Generic Function Method ................................................................. 297
13.10.7 Previewing a Generic Function Call................................................................... 297
13.11 CLIPS Object-Oriented Language (COOL) Commands ............................................. 298
13.11.1 Class Commands ................................................................................................ 298
13.11.2 Message-handler Commands.............................................................................. 303
13.11.3 Definstances Commands .................................................................................... 305
13.11.4 Instances Commands .......................................................................................... 306
13.12 Defmodule Commands ................................................................................................ 308
13.12.1 Displaying the Text of a Defmodule .................................................................. 309
13.12.2 Displaying the List of Defmodules..................................................................... 309
13.13 Memory Management Commands .............................................................................. 309
13.13.1 Determining the Amount of Memory Used by CLIPS ....................................... 309
CLIPS Basic Programming Guide
ix
CLIPS Reference Manual
13.13.2 Determining the Number of Memory Requests Made by CLIPS ...................... 309
13.13.3 Releasing Memory Used by CLIPS ................................................................... 310
13.13.4 Conserving Memory ........................................................................................... 310
13.14 External Text Manipulation ......................................................................................... 310
13.14.1 External Text File Format .................................................................................. 310
13.14.2 External Text Manipulation Functions ............................................................... 312
13.15 Profiling Commands .................................................................................................... 315
13.15.1 Setting the Profiling Report Threshold............................................................... 315
13.15.2 Getting the Profiling Report Threshold .............................................................. 315
13.15.3 Resetting Profiling Information .......................................................................... 315
13.15.4 Displaying Profiling Information ....................................................................... 316
13.15.5 Profiling Constructs and User Functions ............................................................ 316
Appendix A: Support Information ......................................................................................... 319
A.1 Questions and Information ............................................................................................. 319
A.2 Documentation................................................................................................................ 319
A.3 CLIPS Source Code and Executables ............................................................................. 319
Appendix B: Update Release Notes......................................................................................... 321
B.1 Version 6.30 .................................................................................................................... 321
B.2 Version 6.24 .................................................................................................................... 322
B.3 Version 6.23 .................................................................................................................... 324
B.4 Version 6.22 .................................................................................................................... 325
B.5 Version 6.21 .................................................................................................................... 325
B.6 Version 6.2 ...................................................................................................................... 326
Appendix C: Glossary .............................................................................................................. 329
Appendix D: Performance Considerations ............................................................................ 339
D.1 Ordering of Patterns on the LHS .................................................................................... 339
D.2 Deffunctions versus Generic Functions .......................................................................... 341
D.3 Ordering of Method Parameter Restrictions ................................................................... 341
D.4 Instance-Addresses versus Instance-Names ................................................................... 341
D.5 Reading Instance Slots Directly ..................................................................................... 341
Appendix E: CLIPS Warning Messages ................................................................................ 343
Appendix F: CLIPS Error Messages ...................................................................................... 345
Appendix G: CLIPS BNF ........................................................................................................ 383
Appendix H: Reserved Function Names ................................................................................ 393
Appendix I: Bibliography of CLIPS Publications ................................................................. 399
x
Table of Contents
CLIPS Reference Manual
Index ........................................................................................................................................... 407
CLIPS Basic Programming Guide
xi
CLIPS Reference Manual
License Information
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the “Software”), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or
sell copies of the Software, and to permit persons to whom the Software is furnished to do so.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL
THE AUTHORS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL
DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
CLIPS Basic Programming Guide
i
CLIPS Reference Manual
Preface
The History of CLIPS
The origins of the C Language Integrated Production System (CLIPS) date back to 1984 at
NASA’s Johnson Space Center. At this time, the Artificial Intelligence Section had developed
over a dozen prototype expert systems applications using state-of-the-art hardware and software.
However, despite extensive demonstrations of the potential of expert systems, few of these
applications were put into regular use. This failure to provide expert systems technology within
NASA’s operational computing constraints could largely be traced to the use of LISP as the base
language for nearly all expert system software tools at that time. In particular, three problems
hindered the use of LISP based expert system tools within NASA: the low availability of LISP
on a wide variety of conventional computers, the high cost of state-of-the-art LISP tools and
hardware, and the poor integration of LISP with other languages (making embedded applications
difficult).
The Artificial Intelligence Section felt that the use of a conventional language, such as C, would
eliminate most of these problems, and initially looked to the expert system tool vendors to
provide an expert system tool written using a conventional language. Although a number of tool
vendors started converting their tools to run in C, the cost of each tool was still very high, most
were restricted to a small variety of computers, and the projected availability times were
discouraging. To meet all of its needs in a timely and cost effective manner, it became evident
that the Artificial Intelligence Section would have to develop its own C based expert system tool.
The prototype version of CLIPS was developed in the spring of 1985 in a little over two months.
Particular attention was given to making the tool compatible with expert systems under
development at that time by the Artificial Intelligence Section. Thus, the syntax of CLIPS was
made to very closely resemble the syntax of a subset of the ART expert system tool developed
by Inference Corporation. Although originally modelled from ART, CLIPS was developed
entirely without assistance from Inference or access to the ART source code.
The original intent for CLIPS was to gain useful insight and knowledge about the construction of
expert system tools and to lay the groundwork for the construction of a replacement tool for the
commercial tools currently being used. Version 1.0 demonstrated the feasibility of the project
concept. After additional development, it became apparent that CLIPS would be a low cost
expert system tool ideal for the purposes of training. Another year of development and internal
use went into CLIPS improving its portability, performance, functionality, and supporting
documentation. Version 3.0 of CLIPS was made available to groups outside of NASA in the
summer of 1986.
CLIPS Basic Programming Guide
iii
CLIPS Reference Manual
Further enhancements transformed CLIPS from a training tool into a tool useful for the
development and delivery of expert systems as well. Versions 4.0 and 4.1 of CLIPS, released
respectively in the summer and fall of 1987, featured greatly improved performance, external
language integration, and delivery capabilities. Version 4.2 of CLIPS, released in the summer of
1988, was a complete rewrite of CLIPS for code modularity. Also included with this release
were an architecture manual providing a detailed description of the CLIPS software architecture
and a utility program for aiding in the verification and validation of rule-based programs.
Version 4.3 of CLIPS, released in the summer of 1989, added still more functionality.
Originally, the primary representation methodology in CLIPS was a forward chaining rule language based on the Rete algorithm (hence the Production System part of the CLIPS acronym).
Version 5.0 of CLIPS, released in the spring of 1991, introduced two new programming
paradigms: procedural programming (as found in languages such as C and Ada) and
object-oriented programming (as found in languages such as the Common Lisp Object System
and Smalltalk). The object-oriented programming language provided within CLIPS is called the
CLIPS Object-Oriented Language (COOL). Version 5.1 of CLIPS, released in the fall of 1991,
was primarily a software maintenance upgrade required to support the newly developed and/or
enhanced X Window, MS-DOS, and Macintosh interfaces. Version 6.0 of CLIPS, released in
1993, provided support for the development of modular programs and tight integration between
the object-oriented and rule-based programming capabilities of CLIPS. Version 6.1 of CLIPS,
released in 1998, removed support for older non-ANSI C Compilers and added support for C++
compilers. Commands to profile the time spent in constructs and user-defined functions were
also added. Version 6.2 of CLIPS, released in 2002, added support for multiple environments
into which programs can be loaded and improved Windows XP and MacOS development
interfaces.
Because of its portability, extensibility, capabilities, and low cost, CLIPS has received
widespread acceptance throughout the government, industry, and academia. The development of
CLIPS has helped to improve the ability to deliver expert system technology throughout the
public and private sectors for a wide range of applications and diverse computing environments.
CLIPS is being used by numerous users throughout the public and private community including:
all NASA sites and branches of the military, numerous federal bureaus, government contractors,
universities, and many private companies.
CLIPS is now maintained as public domain software by the main program authors who no longer
work for NASA. See appendix A of the Basic Programming Guide for information on obtaining
CLIPS and support.
CLIPS Version 6.3
Version 6.3 of CLIPS contains one major enhancement (improved rule performance) and several
minor enhancements/changes. For a detailed listing of differences between releases of CLIPS,
iv
Preface
CLIPS Reference Manual
refer to appendix B of the Basic Programming Guide and appendix B of the Advanced
Programming Guide.
CLIPS Documentation
Two documents are provided with CLIPS.
•
•
The CLIPS Reference Manual which is split into the following parts:
•
Volume I - The Basic Programming Guide, which provides the definitive description of
CLIPS syntax and examples of usage.
•
Volume II - The Advanced Programming Guide, which provides detailed discussions of
the more sophisticated features in CLIPS and is intended for people with extensive
programming experience who are using CLIPS for advanced applications.
•
Volume III - The Interfaces Guide, which provides information on machine-specific
interfaces.
The CLIPS User’s Guide which provides an introduction to CLIPS rule-based and
object-oriented programming and is intended for people with little or no expert system
experience.
CLIPS Basic Programming Guide
v
CLIPS Reference Manual
Acknowledgements
As with any large project, CLIPS is the result of the efforts of numerous people. The primary
contributors have been: Robert Savely, who conceived the project and provided overall direction
and support; Chris Culbert, who managed the project and wrote the original CLIPS Reference
Manual; Gary Riley, who designed and developed the rule-based portion of CLIPS, co-authored
the CLIPS Reference Manual, and developed the Macintosh interface for CLIPS; Brian Dantes,
who designed and developed the CLIPS Object Oriented Language (COOL) and co-authored the
CLIPS Reference Manual; Bebe Ly, who developed the X Window interface for CLIPS; Chris
Ortiz, who developed the original Windows 95 interface for CLIPS; Dr. Joseph Giarratano of the
University of Houston-Clear Lake, who wrote the CLIPS User’s Guide; and Frank Lopez, who
designed and developed CLIPS version 1.0 and wrote the CLIPS 1.0 User’s Guide.
Many other individuals contributed to the design, development, review, and general support of
CLIPS, including: Jack Aldridge, Carla Colangelo, Paul Baffes, Ann Baker, Stephen
Baudendistel, Les Berke, Tom Blinn, Marlon Boarnet, Dan Bochsler, Bob Brown, Barry
Cameron, Tim Cleghorn, Major Paul Condit, Major Steve Cross, Andy Cunningham, Dan
Danley, Mark Engelberg, Kirt Fields, Ken Freeman, Kevin Greiner, Ervin Grice, Sharon Hecht,
Patti Herrick, Mark Hoffman, Grace Hua, Gordon Johnson, Phillip Johnston, Sam Juliano, Ed
Lineberry, Bowen Loftin, Linda Martin, Daniel McCoy, Terry McGregor, Becky McGuire, Scott
Meadows, C. J. Melebeck, Paul Mitchell, Steve Mueller, Bill Paseman, Cynthia Rathjen, Eric
Raymond, Reza Razavipour, Marsha Renals, Monica Rua, Tim Saito, Michael Sullivan, Gregg
Swietek, Eric Taylor, James Villarreal, Lui Wang, Bob Way, Jim Wescott, Charlie Wheeler, and
Wes White.
CLIPS Basic Programming Guide
vii
CLIPS Reference Manual
Section 1:
Introduction
This manual is the Basic Programming Guide for CLIPS. It is intended for users interested in the
syntax of CLIPS. No previous expert system background is required, although a general
understanding of computer languages is assumed. Section 2 of this manual provides an overview
of the CLIPS language and basic terminology. Sections 3 through 11 provide additional details
regarding the CLIPS programming language on topics such as rules and the CLIPS Object
Oriented Programming Language (COOL). The types of actions and functions provided by
CLIPS are defined in section 12. Finally, commands typically used from the CLIPS interactive
interface are described in section 13.
The Basic Programming Guide documents just the basic CLIPS syntax. More advanced
capabilities, such as user-defined functions, embedded applications, etc., are documented more
fully in the Advanced Programming Guide. The Advanced Programming Guide is intended for
users who have a complete knowledge of the CLIPS syntax and a programming background. It is
not necessary to read the Advanced Programming Guide to learn how to use CLIPS. CLIPS can
be learned and simple expert systems can be built with the information provided in this manual.
CLIPS Basic Programming Guide
1
CLIPS Reference Manual
Section 2:
CLIPS Overview
This section gives a general overview of CLIPS and of the basic concepts used throughout this
manual.
2.1 Interacting with CLIPS
CLIPS expert systems may be executed in three ways: interactively using a simple, text-oriented,
command prompt interface; interactively using a window/menu/mouse interface on certain machines; or as embedded expert systems in which the user provides a main program and controls
execution of the expert system. Embedded applications are discussed in the Advanced
Programming Guide. In addition, a series of commands can be automatically read directly from a
file when CLIPS is first started or as the result of the batch command.
The generic CLIPS interface is a simple, interactive, text-oriented, command prompt interface
for high portability. The standard usage is to create or edit a knowledge base using any standard
text editor, save the knowledge base as one or more text files, exit the editor and execute CLIPS,
then load the knowledge base into CLIPS. The interface provides commands for viewing the
current state of the system, tracing execution, adding or removing information, and clearing
CLIPS.
A more sophisticated window interface is available for the Macintosh, Windows 3.1, and X
Window environments. All interface commands described in this section are available in the
window interfaces. These interfaces are described in more detail in the Interfaces Guide.
2.1.1 Top Level Commands
The primary method for interacting with CLIPS in a non-embedded environment is through the
CLIPS command prompt (or top level). When the “CLIPS>” prompt is printed, a command
may be entered for evaluation. Commands may be function calls, constructs, local or global
variables, or constants. If a function call is entered (see section 2.3.2), that function is evaluated
and its return value is printed. Function calls in CLIPS use a prefix notation—the operands to a
function always appear after the function name. Entering a construct definition (see section
2.3.3) at the CLIPS prompt creates a new construct of the appropriate type. Entering a global
variable (see section 2.4.3) causes the value of the global variable to be printed. Local variables
can be set at the command prompt using the bind function and retain their value until a reset or
clear command is issued. Entering a local variable at the command prompt causes the value of
CLIPS Basic Programming Guide
3
CLIPS Reference Manual
the local variable to be printed. Entering a constant (see section 2.3.1) at the top level causes the
constant to be printed (which is not very useful). For example,
CLIPS (V6.30 3/11/15)
CLIPS> (+ 3 4)
7
CLIPS> (defglobal ?*x* = 3)
CLIPS> ?*x*
3
CLIPS> red
red
CLIPS> (bind ?a 5)
5
CLIPS> (+ ?a 3)
8
CLIPS> (reset)
CLIPS> ?a
[EVALUATN1] Variable a is unbound
FALSE
CLIPS>
The previous example first called the addition function adding the numbers 3 and 4 to yield the
result 7. A global variable ?*x* was then defined and given the value 3. The variable ?*x* was
then entered at the prompt and its value of 3 was returned. Finally the constant symbol red was
entered and was returned (since a constant evaluates to itself).
2.1.2 Automated Command Entry and Loading
Some operating systems allow additional arguments to be specified to a program when it begins
execution. When the CLIPS executable is started under such an operating system, CLIPS can be
made to automatically execute a series of commands read directly from a file or to load
constructs from a file. The command-line syntax for starting CLIPS and automatically reading
commands or loading constructs from a file is as follows:
Syntax
clips