CSC151 2009F, Class 28: Recursion with Helper Procedures
Admin:
* Yes, we will have a quiz on Friday.
* It will be on recursion
* It will probably include helper recursion
* Assignment 6 due now!
* No, you don't get an assignment 7 to do over fall break.
* Reading for Friday: List Recursion, Revisited.
Overview:
* Delayed evaluation in recursive procedures.
* A strategy: Carry along intermediate results.
* Using recursive helpers.
* A term: Tail recursion.
Whiteboard (or outline) shows one way to compute sum. We need to
code it up
(define sum
(lambda (lst)
(sum-as-you-go (car lst) (cdr lst))))
(define sum-as-you-go
(lambda (partial-sum lst)
(if (null? lst)
partial-sum
(sum-as-you-go (+ partial-sum (car lst)) (cdr lst)))))
* Term: Tail-recursion
* The form of recutrsion in sum-as-you-go
* The recursive call is the "tail" of the procedure; the last thing done