{"id":2986,"date":"2023-01-11T10:55:37","date_gmt":"2023-01-11T05:25:37","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=2986"},"modified":"2023-01-11T10:55:37","modified_gmt":"2023-01-11T05:25:37","slug":"book-review-adventures-in-rule-based-programming-a-clips-tutorial","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2023\/01\/11\/book-review-adventures-in-rule-based-programming-a-clips-tutorial\/","title":{"rendered":"Book Review: Adventures in Rule-Based Programming &#8211; A CLIPS Tutorial"},"content":{"rendered":"<p><em><span style=\"color: #0000ff;\"><strong>Title:<\/strong><\/span><\/em> Adventures in Rule-Based Programming &#8211; A CLIPS Tutorial<br \/>\n<em><strong><span style=\"color: #0000ff;\">Author:<\/span><\/strong> <\/em>Gary Riley<br \/>\n<em><strong><span style=\"color: #0000ff;\">Publisher:<\/span><\/strong><\/em> Secret Society Software, LLC<br \/>\n<em><span style=\"color: #0000ff;\"><strong>Year:<\/strong><\/span><\/em> 2022<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/01\/Cover.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2987\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/01\/11\/book-review-adventures-in-rule-based-programming-a-clips-tutorial\/cover\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/01\/Cover.png\" data-orig-size=\"622,994\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Cover\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/01\/Cover.png\" class=\"alignleft wp-image-2987 \" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/01\/Cover.png?resize=94%2C150&#038;ssl=1\" alt=\"\" width=\"94\" height=\"150\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/01\/Cover.png?resize=188%2C300&amp;ssl=1 188w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/01\/Cover.png?w=622&amp;ssl=1 622w\" sizes=\"(max-width: 94px) 100vw, 94px\" \/><\/a>In an earlier <a href=\"https:\/\/www.rangakrish.com\/index.php\/2022\/12\/08\/are-rule-based-systems-still-relevant-today\/\" target=\"_blank\" rel=\"noopener\"><em><strong>article<\/strong><\/em><\/a>, I had talked about the relevance of <em><strong>Rule-based<\/strong><\/em> systems today. In that article I had also listed a few <em><strong>Rule engines<\/strong><\/em> that are popular and widely used. One of them is <a href=\"https:\/\/clipsrules.net\" target=\"_blank\" rel=\"noopener\"><em><strong>CLIPS<\/strong><\/em><\/a>, an <a href=\"https:\/\/en.wikipedia.org\/wiki\/OPS5\" target=\"_blank\" rel=\"noopener\"><em><strong>OPS5<\/strong><\/em><\/a> inspired rule engine written in <em><strong>C<\/strong><\/em> language.<\/p>\n<p>Gary Riley, the author of the book, was part of the team at <em><strong>NASA<\/strong><\/em> that originally created <em><strong>CLIPS<\/strong><\/em> in the 1980s. After leaving <em><strong>NASA<\/strong><\/em> in 1996, he continues to independently support the software in its current public domain form.<\/p>\n<p>The present book is an excellent addition to the official documentation: User Guide, Basic Programming Guide, Advanced Programming Guide, and Interfaces Guide. With such good documentation already available, what is the need for a book like this? If you are new to <em><strong>CLIPS<\/strong><\/em> or would just like to know what you can do with a <em><strong>Rule engine<\/strong><\/em>, then this book is a great place to start your journey. You might also want to take a look at another book [1] that he co-authored many years ago on <em><strong>Expert Systems<\/strong><\/em>.<\/p>\n<p>This book teaches <em><strong>CLIPS<\/strong><\/em> using the example of an interactive <em><strong>Text Adventure<\/strong><\/em> (also called <a href=\"https:\/\/en.wikipedia.org\/wiki\/Interactive_fiction\" target=\"_blank\" rel=\"noopener\"><em><strong>Interactive Fiction<\/strong><\/em><\/a>) game. This is a well-chosen and somewhat off-beat example in my opinion that makes the book even more interesting.<\/p>\n<p><strong>Chapter 1<\/strong> lays the foundation by introducing <em><strong>Rule-based<\/strong> <\/em>programming. Then it talks about <em><strong>Text Adventure<\/strong><\/em> games and some tools available for building them. The chapter concludes by showing how to install <em><strong>CLIPS<\/strong><\/em> environment and how to interact with the <em><strong>CLIPS<\/strong><\/em> shell.<\/p>\n<p><strong>Chapter 2<\/strong> explains the concrete syntax of <em><strong>Rules<\/strong><\/em>, <em><strong>Patterns<\/strong><\/em>, <em><strong>Constraints<\/strong><\/em>, and <em><strong>Fact templates<\/strong><\/em> in <em><strong>CLIPS<\/strong><\/em>. It also shows how the <em><strong>\u201cagenda\u201d<\/strong><\/em> keeps track of rule activations. <strong>Chapter 3<\/strong> extends this further by discussing how to organize the rules in the file system and how to load them. The <em><strong>\u201cBatch\u201d<\/strong> <\/em>and a few other commands are introduced in this context. The significance of the <em><strong>\u201cSalience\u201d<\/strong> <\/em>property of rules is also touched upon. The <em><strong>Text Adventure<\/strong> <\/em>example is developed gradually, incorporating the <em><strong>CLIPS<\/strong><\/em> features discussed in the chapter.<\/p>\n<p><strong>Chapters 4<\/strong> and <strong>5<\/strong> discuss more advanced features of rules such as complex constraints involving predicates and patterns. When many rules have a similar structure, the author shows how such rules can be generalized to reduce the number of rules. This is somewhat similar to the <em><strong>\u201cgeneric\u201d<\/strong><\/em> functions in traditional programming languages.<\/p>\n<p><strong>Chapter 6<\/strong> is devoted to a detailed exposition of <em><strong>\u201cFacts\u201d<\/strong><\/em>. Various operations and queries on the facts database are demonstrated in the context of the game being developed. The <em><strong>\u201cfind-all-facts\u201d<\/strong><\/em> function, for example, retrieves all facts in the database that match the given pattern. Its counterpart, the <em><strong>\u201cdo-for-all-facts\u201d<\/strong><\/em> function, can be used to apply a sequence of operations on a collection of facts that match a pattern.<\/p>\n<p><strong>Chapter 7<\/strong> covers <em><strong>\u201cModules\u201d<\/strong><\/em>, a useful feature for organizing rules in the knowledge base. In a medium to large project, it is common (in fact, necessary) to define several modules and keep logically related rules in the same package. This minimizes the need for unnecessarily associating <em><strong>\u201csalience\u201d<\/strong><\/em> with possibly conflicting rules, and it additionally allows <em><strong>CLIPS<\/strong><\/em> engine to use stack-based <em><strong>\u201cagenda\u201d<\/strong><\/em> for deciding what rule to fire next. To put this idea into practice, the author shows how it is possible to group the rules corresponding to the <em><strong>Text Adventures<\/strong><\/em> game into different modules.<\/p>\n<p><em><strong>Chapter 8<\/strong><\/em>, the last chapter in the book, describes some finer and practical aspects of developing applications with <em><strong>CLIPS<\/strong><\/em>. How to save session data and restore the state at a later point in time is one of the topics explained here. This is particularly relevant in the context of the game covered in the book. Developing a <em><strong>CLIPS<\/strong><\/em> project, like any other non-trivial application in other languages, tends to be iterative, where features are added and then tested. The <em><strong>\u201cbatch\u201d<\/strong><\/em> command is a convenient way to automatically execute a series of commands in the context of regression testing. Once the functionality is completed and rules have been fully tested, it is quite likely that this <em><strong>\u201creasoning engine\u201d<\/strong><\/em> will be embedded as part of a larger application (I have used <em><strong>CLIPS<\/strong><\/em> in embedded mode in one of my applications). <em><strong>Chapter 8<\/strong> <\/em>covers these three areas in sufficient detail.<\/p>\n<p>By the time you complete the book, you will have a good working knowledge of <em><strong>CLIPS<\/strong><\/em> and will be ready to use it in your own project. Of course, you may need to consult the official documentation for other finer details in case you get stuck at some point.<\/p>\n<p>I congratulate the author for coming out with such an eminently readable book on <em><strong>CLIPS<\/strong><\/em>!<\/p>\n<p>Have a great day!<\/p>\n<p style=\"text-align: center;\"><strong>References<\/strong><\/p>\n<p>1) <em><strong>Expert Systems: Principles and Programming<\/strong><\/em>, Joseph C. Giarratano and Gary D. Riley, 4th Edition, 2005, Thomson Course Tehnology.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Title: Adventures in Rule-Based Programming &#8211; A CLIPS Tutorial Author: Gary Riley Publisher: Secret Society Software, LLC Year: 2022 In an earlier article, I had talked about the relevance of Rule-based systems today. In that article I had also listed a few Rule engines that are popular and widely used. One of them is CLIPS, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[162,17],"tags":[347,340,341],"class_list":["post-2986","post","type-post","status-publish","format-standard","hentry","category-knowledge-representation","category-programming","tag-clips","tag-rule-engine","tag-rule-based-system"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-Ma","jetpack-related-posts":[{"id":2960,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/12\/08\/are-rule-based-systems-still-relevant-today\/","url_meta":{"origin":2986,"position":0},"title":"Are Rule-Based Systems Still Relevant Today?","author":"admin","date":"December 8, 2022","format":false,"excerpt":"Before Machine Learning came into the mainstream, Rule-based systems were being used actively to solve complex decision making problems. In fact, Rule engines were considered to be an exotic component of Artificial Intelligence and the systems built using these rule engines were called Expert Systems. I still remember learning to\u2026","rel":"","context":"In &quot;Knowledge Representation&quot;","block_context":{"text":"Knowledge Representation","link":"https:\/\/www.rangakrish.com\/index.php\/category\/knowledge-representation\/"},"img":{"alt_text":"Gathering Symptom Information","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/12\/Screen1-300x187.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":617,"url":"https:\/\/www.rangakrish.com\/index.php\/2017\/09\/13\/reuse-of-grammars-through-inheritance\/","url_meta":{"origin":2986,"position":1},"title":"Reuse of Grammars Through Inheritance","author":"admin","date":"September 13, 2017","format":false,"excerpt":"We are familiar with the advantages of class inheritance in object-oriented languages such as C++, C#, Java, and Python. The ability to reuse functionality via inheritance allows us to express our software design optimally, without having to write redundant code. iLangGen encourages the reuse of grammars by supporting Grammar Inheritance,\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Simple Grammar","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/09\/image1.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/09\/image1.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/09\/image1.png?resize=525%2C300 1.5x"},"classes":[]},{"id":4265,"url":"https:\/\/www.rangakrish.com\/index.php\/2026\/03\/22\/counting-sentences-an-implementation-in-c20\/","url_meta":{"origin":2986,"position":2},"title":"Counting Sentences: An Implementation in C++20","author":"admin","date":"March 22, 2026","format":false,"excerpt":"Counting the number of sentences in a given paragraph appears rather simple on the surface - look for the common punctuation marks: \u201c.?!\u201d. Only when you dig deeper, you will know that it is really not that simple. For example, consider this text: \u201cPeter met Dr.James at 3 p.m.\u201d How\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Regular Expressions","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/03\/regex-300x91.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/03\/regex-300x91.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/03\/regex-300x91.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2927,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/10\/20\/why-learn-lisp\/","url_meta":{"origin":2986,"position":3},"title":"Why Learn Lisp?","author":"admin","date":"October 20, 2022","format":false,"excerpt":"In the last article, I had shared my views on why programmers should learn Prolog, preferably as the first language. What language should one learn next? I strongly pitch for Lisp, to be precise, \u201cCommon Lisp\u201d. Lisp happens to be the second oldest (1958) programming language, only after Fortran (1957)!\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":534,"url":"https:\/\/www.rangakrish.com\/index.php\/2017\/05\/22\/definite-clause-grammars-dcg-in-lisp\/","url_meta":{"origin":2986,"position":4},"title":"Definite Clause Grammars (DCG) in Lisp","author":"admin","date":"May 22, 2017","format":false,"excerpt":"Definite Clause Grammars (DCG) are an elegant formalism for specifying context free grammars, and part of their popularity is due to their support in the Prolog language. Most books on Natural Language processing usually include a brief coverage of DCGs, even though Natural languages are not context-free. Because of the\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"DCG Grammar","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/05\/DCG-Grammar.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/05\/DCG-Grammar.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/05\/DCG-Grammar.png?resize=525%2C300 1.5x"},"classes":[]},{"id":1711,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/09\/01\/poetry-in-prolog-part-2\/","url_meta":{"origin":2986,"position":5},"title":"Poetry in Prolog: Part-2","author":"admin","date":"September 1, 2019","format":false,"excerpt":"In an earlier post, I showed how Prolog can be used to generate poetry, making use of my \"iLexicon\". I want to continue the discussion today by giving another example, this time based on the theme of sounds emitted by various animals and birds. As hinted in my previous articles,\u2026","rel":"","context":"In &quot;Natural Language Processing&quot;","block_context":{"text":"Natural Language Processing","link":"https:\/\/www.rangakrish.com\/index.php\/category\/natural-language-processing\/"},"img":{"alt_text":"The DCG Grammar","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/code.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/code.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/code.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2986","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=2986"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2986\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=2986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=2986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=2986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}