Reference Manual

 

Volume I

Basic Programming Guide

 

 

Quicksilver Beta

December 31st 2007

 

 

 

 

 


CLIPS Basic Programming Guide

Quicksilver Beta  December 31st 2007

 

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.......................................................................................................................... 11

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.................................................................................. 17

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........................................................... 19

Section 3 ‑ Deftemplate Construct............................................................................................. 21

3.1 Slot Default Values............................................................................................................ 22

3.2 Slot Default Constraints for Pattern‑Matching................................................................... 22

3.3 Slot Value Constraint Attributes........................................................................................ 23

3.4 Implied Deftemplates......................................................................................................... 23

Section 4 ‑ Deffacts Construct.................................................................................................... 25

Section 5 ‑ Defrule Construct..................................................................................................... 27

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....................................................................................................... 31

5.4 LHS Syntax....................................................................................................................... 33

5.4.1 Pattern Conditional Element...................................................................................... 33

5.4.1.1 Literal Constraints............................................................................................ 34

5.4.1.2 Wildcards Single‑ and Multifield..................................................................... 36

5.4.1.3 Variables Single‑ and Multifield...................................................................... 38

5.4.1.4 Connective Constraints.................................................................................... 40

5.4.1.5 Predicate Constraints........................................................................................ 43

5.4.1.6 Return Value Constraints................................................................................. 45

5.4.1.7 Pattern‑Matching with Object Patterns............................................................. 46

5.4.1.8 Pattern‑Addresses............................................................................................ 49

5.4.2 Test Conditional Element.......................................................................................... 49

5.4.3 Or Conditional Element............................................................................................. 51

5.4.4 And Conditional Element.......................................................................................... 52

5.4.5 Not Conditional Element........................................................................................... 53

5.4.6 Exists Conditional Element....................................................................................... 54

5.4.7 Forall Conditional Element........................................................................................ 56

5.4.8 Logical Conditional Element..................................................................................... 58

5.4.9 Automatic Addition and Reordering of LHS CEs..................................................... 61

5.4.9.1 Rules Without Any LHS Pattern CEs.............................................................. 61

5.4.9.2 Test and Not CEs as the First CE of an And CE.............................................. 61

5.4.9.3 Test CEs Following Not CEs........................................................................... 62

5.4.9.4 Or CEs Following Not CEs............................................................................. 63

5.4.9.5 Notes About Pattern Addition and Reordering................................................ 63

5.4.10 Declaring Rule Properties....................................................................................... 63

5.4.10.1 The Salience Rule Property............................................................................ 64

5.4.10.2 The Auto‑Focus Rule Property...................................................................... 65

Section 6 ‑ Defglobal Construct.................................................................................................. 67

Section 7 ‑ Deffunction Construct.............................................................................................. 73

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.......................................................................... 81

8.5.2 Method Precedence................................................................................................... 82

8.5.3 Shadowed Methods.................................................................................................. 85

8.5.4 Method Execution Errors.......................................................................................... 85

8.5.5 Generic Function Return Value................................................................................. 85

Section 9 ‑ CLIPS Object Oriented Language (COOL)........................................................... 87

9.1 Background........................................................................................................................ 87

9.2 Predefined System Classes................................................................................................ 87

9.3 Defclass Construct............................................................................................................. 88

9.3.1 Multiple Inheritance.................................................................................................. 89

9.3.1.1 Multiple Inheritance Rules............................................................................... 90

9.3.2 Class Specifiers......................................................................................................... 92

9.3.2.1 Abstract and Concrete Classes......................................................................... 92

9.3.2.2 Reactive and Non‑Reactive Classes................................................................. 92

9.3.3 Slots.......................................................................................................................... 92

9.3.3.1 Slot Field Type................................................................................................. 93

9.3.3.2 Default Value Facet.......................................................................................... 93

9.3.3.3 Storage Facet.................................................................................................... 94

9.3.3.4 Access Facet.................................................................................................... 95

9.3.3.5 Inheritance Propagation Facet.......................................................................... 96

9.3.3.6 Source Facet..................................................................................................... 97

9.3.3.7 Pattern‑Match Reactivity Facet......................................................................... 98

9.3.3.8 Visibility Facet................................................................................................. 99

9.3.3.9 Create‑Accessor Facet.................................................................................... 100

9.3.3.10 Override‑Message Facet.............................................................................. 101

9.3.3.11 Constraint Facets.......................................................................................... 101

9.3.4 Message‑handler Documentation............................................................................ 102

9.4 Defmessage‑handler Construct........................................................................................ 103

9.4.1 Message‑handler Parameters................................................................................... 105

9.4.1.1 Active Instance Parameter.............................................................................. 105

9.4.2 Message‑handler Actions........................................................................................ 106

9.4.3 Daemons................................................................................................................. 108

9.4.4 Predefined System Message‑handlers..................................................................... 108

9.4.4.1 Instance Initialization...................................................................................... 108

9.4.4.2 Instance Deletion............................................................................................ 109

9.4.4.3 Instance Display............................................................................................. 110

9.4.4.4 Directly Modifying an Instance...................................................................... 110

9.4.4.5 Modifying an Instance using Messages......................................................... 111

9.4.4.6 Directly Duplicating an Instance.................................................................... 111

9.4.4.7 Duplicating an Instance using Messages........................................................ 112

9.4.4.8 Instance Creation............................................................................................ 112

9.5 Message Dispatch............................................................................................................ 112

9.5.1 Applicability of Message‑handlers.......................................................................... 113

9.5.2 Message‑handler Precedence.................................................................................. 113

9.5.3 Shadowed Message‑handlers.................................................................................. 114

9.5.4 Message Execution Errors...................................................................................... 114

9.5.5 Message Return Value............................................................................................ 115

9.6 Manipulating Instances.................................................................................................... 115

9.6.1 Creating Instances................................................................................................... 115

9.6.1.1 Definstances Construct.................................................................................. 117