CSC151 2007S, Class 15: Recursion with Natural Numbers (2)
Admin:
* Reading for Friday: Local Bindings with let.
* EC: For supporting Grinnell's Ultimate Teams (Grinnellephants and
Sticky Tongues) at their meet in Baton Rouge this weekend.
* EC: Track meet at UIowa Friday afternoon (3ish)
Overview:
* Q & A.
* Lab.
* Reflection.
Problem, midway through the lab, iota
(define iota
(lambda (n)
(if (zero? n)
null
(cons n (iota (- n 1))))))
Reflection - Why did I ask for the second definition of iota, in terms
of count-from?
* Remember that you can solve many problems by relying on previously
solved problems.
* To point out a potential flaw in count-from - it doesn't work correctly if
the upper bound is less than the lower bound
* Worry about "boundary cases"
Nesting lists: Which is better?
(define nest
(lambda (val depth)
(if (zero? depth)
val
(list (nest val (- depth 1))))))
(define nest
(lambda (val depth)
(if (zero? depth)
val
(nest (list val) (- depth 1)))))