The Department of Computer Science & Engineering
cse@buffalo

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 26: SEQUENCES
Corrections
Page 304, lines 13 - 28: Change

(defun substitute (pat subs)
  "Returns a tree like PAT,
   but with every variable that is bound in
   the substitution SUBS
   replaced by the term it is bound to."
  (check-type subs list)
  (cond ((atom pat)
         (if (and (variablep pat) (boundp pat subs))
             (bound-to pat subs)
             pat))
        ((and (svariablep (first pat))
              (boundp (first pat) subs))
         (append (bound-to (first pat) subs)
                 (substitute (rest pat) subs)))
        (t (cons (substitute (first pat) subs)
                 (substitute (rest pat) subs)))))
to

(defun substitute (pat subs)
  "Returns a tree like PAT,
                but with every variable that is bound in
                the substitution SUBS
                replaced by the term it is bound to."
  ;; pat cannot be a sequence variable because there might be no
  ;; environment to splice its value into.
  (check-type pat (not (satisfies svariablep)))
  (check-type subs list)
  (cond ((atom pat)
	 (if (and (variablep pat) (boundp pat subs))
	     (bound-to pat subs)
	   pat))
	((svariablep (first pat))
	 (if (boundp (first pat) subs)
	     (append (bound-to (first pat) subs)
		     (substitute (rest pat) subs))
	   (cons (first pat) (substitute (rest pat) subs))))
	(t (cons (substitute (first pat) subs)
		 (substitute (rest
			      pat) subs)))))

Notes
  1. Read Chapter 26.

  2. Do Exercises 26.1 - 26.4 as you need to in order to understand the material. Notice that the answer to 26.4 is given in Appendix A.

  3. You may want to review the dvi or PostScript version of the overview and specification of Project P1.

  4. Do Exercises 26.8, 26.9, 26.12, 26.13, and 26.14. Note that, as part of Exercise 26.14, you should redefine the *grammar-rules* parameter to be the set of rules shown on page 195. Submit your updated version of match.cl

  5. Do Exercises 26.10 and 26.11, but you needn't submit anything for them.

  6. When you have submitted correct exercises through this chapter, you will have earned a grade of B+.

Next

Copyright © 1999, 2000 by Stuart C. Shapiro. All rights reserved.

Stuart C. Shapiro <shapiro@cse.buffalo.edu>