41.clp ------- Contains an example of how a list can be processed. It uses a fact "find-child" to identify (search) a certain child from a list of childrens Because of that it looks a bit odd. If one uncomments line 19 and comments lines 23 and 18 we can see anonymous variables at work ($?). Those are used when we are not interested in the values that the anonymous variables are replacing. $? will be used for anonymous multislot variables (lists) ? will be used for plain anonymous variables (all the other datatypes) --------------------------------------------------------------------------- 42.clp ------- An example of a stack and operations with it. A first in the deffacts construct we can see the usual behaviour of CLIPS exemplified, that is NO FACT DUPLICATION. Although there are 6 (pop-value) facts in there, actually only one remains when we add them in the working memory. The rule "push-value" makes out of the fact on line 16 and the list on line 17 a single fact, the new list, on line 21. The pop-value-valid rule pops a value from the stack. It is entirely commented, because we can use it even without the lines 28 and 29 if the stack is not empty. So we can try it like that by uncommenting all the other lines and leaving lines 28 and 29 commented. It is much simpler to understand without those lines, because it doesn't require the length$ function which returns the length of a list. This variant of the rule together with the next rule should work, because the condition on line 30 is only valid if we have exactly one valid value before the multislot variable $?rest The rule popall pops all the values from a stack and could be written much more simple but is like that to also produce the message in the case of the empty stack. We can also learn from it the nth$ function which returns the n-th element of a list and the rest$ function which returns everything else from the list after extracting the 1st element --------------------------------------------------------------------------- 43.clp, 44.clp and 46.clp ------------------------- Introduce constraints and the elements we can use to write them: ~ the negation | or & and If we want to also extract the value from that field into a variable, the syntax is ?x & constraint where ?x is the variable and whose value we have the constraint. A logical constraint would look like in the following example ?x &:(< ?x 5) meaning the variable ?x has to be less than 5 Another example: ?size&:(> ?size 1)&:(< ?size 5) meaning the variable ?size is between 1 and 5 (example taken fron 46.clp) --------------------------------------------------------------------------- 45.clp ------- Introduces the progn$ function, which repeats an action on all the elements of a list. It will produce the average of the list's elements if you call it like this: (addthem 1 2 3 4) --------------------------------------------------------------------------- 47.clp ------- An example of how infinite loops can appear. It also introduces rule priority. salience is by default 0 which is the normal priority -10000 is the lowest priority possible 10000 is the highest priority possible The commented rule produces an infinite loop because it will always try to add the "first" fact's area to the sum. This is because when we delete the old sum, the new one is matched again with the first rectangle. This al almoast true, because in anothe "strategy" that we saw last week, the rule might not be placed at the begining of the agenda and so another fact is added next, but still we will have the infinite loop.