CLIPS Basic Programming Guide Version 6.30 March 17Th 2015
Total Page:16
File Type:pdf, Size:1020Kb
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