[an error occurred while processing this directive]

Class 6 Notes

Lecture Slides, Suitable For Printing

List Procedures Practice

(define (list-cruncher base proc combiner lst)
  (if (null? lst)
      base
      (combiner (proc (car lst))
                     (list-cruncher base proc combiner 
                                         (cdr lst)))))


(define (sumlist p)

  (list-cruncher _____ ___________________  _____ p))

(define (map f p)

  (list-cruncher _______  ______   ______ p))

(define (length p)

  (list-cruncher ______  _____________ + p))
Why would it be impossible to correctly define list? using just list-cruncher?





Define find-closest-number, a procedure that takes two parameters, a goal and a list of numbers, and produces the number in the list numbers list that is closest to goal.





find-closest

(define (find-closest-number goal numbers)
   (if (= 1 (length numbers))
       (car numbers)
       (if (< (abs (- goal (car numbers)))
              (abs (- goal 
                      (find-closest goal (cdr numbers)))))
           (car numbers)
           (find-closest goal (cdr numbers)))))

(define (find-closest goal lst closeness)
  (if (= 1 (length lst))
      (car lst)
      (if (< (closeness goal (car lst))
             (closeness goal 
                         (find-closest goal (cdr lst) closeness)))
          (car lst)
          (find-closest goal (cdr lst) closeness))))

(define (pick-closest closeness goal num1 num2)
   (if (< (closeness goal num1)
            (closeness goal num2))
       num1
       num2))

(define (find-closest goal lst closeness)
   (if (= 1 (length lst))
 (car lst)
 (pick-closest closeness goal (car lst) 
      (find-closest goal (cdr lst) closeness))))

Languages

How can we compare notations for describing languages?






What is the difference between RTN and BNF?

Music and Recursion

Song ::= Verse VBBD VBBD Better Coda
VBBD ::= Verse Bridge Bridge Dadada (ends on C)
Coda ::= F Eb Bb F Coda
Note: the Coda has no base case, and should continue forever (time permitting).
Challenge Problem
Define a Scheme procedure that can produce the INT and Gplot graphs from GEB Chapter 5. Hint: you may need to think about curves differently from PS3. (A solution is worth up to 5% extra credit on Exam 1.)

Links

Hofstadter's Law: It always takes longer than you expect,
even when you take Hofstadter's Law into account.
[an error occurred while processing this directive]