The Department of Computer Science & Engineering
 STUART C. SHAPIRO: CSE 202

# CSE202:Programming in Lisp

 Course Grades Email Welcome Policies     Grades     Inc     Intgrty Preface Part I   Chap 1   Chap 2   Chap 3   XEmacs   Chap 4   Chap 5   Chap 6   Chap 7   Chap 8   Chap 9 Part II   Chap 10   Chap 11   Chap 12   Chap 13   Chap 14   Chap 15   Chap 16   Chap 17   Chap 18   Chap 19   Chap 20   Chap 21   Chap 22   Chap 23 Part III   Chap 24   Chap 25   Chap 26   Chap 27   Chap 28   Chap 29   Chap 30   Chap 31   Chap 32 CHAPTER 18: RECURSION ON TREES Corrections page 130, lines 1 - 7: Change indentation from ``` (defun bstreep (tree) "A bstree is either an element, or a three-member list, the first of which is an element." (or (typep tree 'util:element) (and (listp tree) (= (length tree) 3) (typep (first tree) 'util:element)))) ``` to ``` (defun bstreep (tree) "A bstree is either an element, or a three-member list, the first of which is an element." (or (typep tree 'util:element) (and (listp tree) (= (length tree) 3) (typep (first tree) 'util:element)))) ``` Page 298, lines 15 - 18: Change ``` (defun lhs (rule) "Returns the right-hand side of the RULE." (check-type rule rule) (first rule)) ``` to ``` (defun lhs (rule) "Returns the left-hand side of the RULE." (check-type rule rule) (first rule)) ``` Notes Read Chapter 18. Do Exercise 18.1 if you are not already comfortable with the difference between `eql` and `equal`. Do Exercises 18.2 through 18.4 if you need to in order to feel more comfortable with recursion on trees. In any case, note the `typecase` function. Do Exercise 18.5. Try both `lisp:equal` and `lisp:tree-equal` on trees at least one of whose leaves is a string. For Exercise 18.6, explore the differences between `equal` and `equalp`. I personally often use `equal`, but seldom use `equalp`. For Exercise 18.7, look in Section B.13.4. The functions that are not explicitly called destructive are not. Do Exercises 18.8 - 18.11 for your own understanding. Don't bother doing Exercises 18.12 - 18.22. Do Exercises 18.23 and 18.24. Submit a file named `ch18.cl` with `flatten` and `flatten2` defined in the `ch18` package. Do Exercises 18.25 - 18.27. Submit your updated match.cl file. Please remember to revise the line "This file satisfies the exercises through Exercise ???" Exercise 18.25 is probably not worded as well as it might be. You should rewrite `match` and `substitute` so that in calls like `(match pat tree)` and ```(substitute pat subs)```, `pat` and `tree` can be arbitrary trees, though only `pat` can contain variables. That is, previously `match` worked on two lists, one of which could contain variables; now it should work on two trees, one of which can contain variables. Remember that, whereas the base case of lists is `nil`, the base case of trees is any atom. Here are some examples of attempts to match trees: ```> (match 'a 'a) ((T T)) > (match 'a 'b) NIL > (match '?x 'a) ((?X A) (T T)) > (match '(?x) 'a) NIL > (match '?x '(a)) ((?X (A)) (T T)) > (match '(a ?x c) '(a b c)) ((?X B) (T T)) > (match '(a (?x) c) '(a b c)) NIL > (match '(a ?x c) '(a (b) c)) ((?X (B)) (T T)) > (match '(a (?x) c) '(a (b) c)) ((?X B) (T T)) ``` When you have submitted correct exercises through this chapter, you will have earned a grade of C+ (above a 2.0).