return 'join(join(clausefor clause in conjunctto produce the desired nested lists and string by combining two steps into one this form might run fasterwe'll leave it to the reader to decide whether it is more difficult to understand as usualwe can test components of this module interactivelyimport rules rules internal(' ?xb'[[' ''? '][' ']rules internal_rule('rule if ?xb then cd ? '{'then'[[' '][' ''? ']]'rule'' ''if'[[' ''? '][' ']] rules internal_rule('rule if ?xb then cd ? 'rules external_rule( 'rule if ?xb then cd ? parsing by splitting strings around tokens like this takes you only so far there is no direct support for recursive nesting of componentsand syntax errors are not handled very gracefully but for simple language tasks like thisstring splitting might be enoughat least for prototyping or experimental systems you can always add more robust rule parser later or reimplement rules as python code or classes more on the holmes expert system shell so how are these rules actually usedas mentionedthe rule parser we just met is part of the python-coded holmes expert system shell holmes is an old system written around and before python it implemented both forward and backward chaining inference over rule sets for examplethe rulerule pylike if ? likes coding? likes spam then ? likes python can be used both to prove whether someone likes python (chaining backwardfrom "thento "if")and to deduce that someone likes python from set of known facts (chaining forwardfrom "ifto "then"deductions may span multiple rulesmultiple clauses represent conjunctionsand rules that name the same conclusion represent alternatives holmes also performs simple pattern-matching along the way to assign the variables that appear in rules ( ? )and it is able to explain both its deductions and questions holmes also served as proof of concept for python in general at time when such evidence was still sometimes necessaryand at last check it still worked unchanged on python platforms howeverits code no longer reflects modern python best practice because of thisi no longer maintain this system today in factit has suffered from bit rot so much and for so long that 've opted not to revisit it for this edition at all its original python code is included in the book examples packagebut it has not been ported to python formand does not accurately reflect python as it exists today that isholmes is an ex-system it has ceased to be and it won' be discussed further here for more modern ai tools and support for pythonsearch the web this is fun text and language