EECS 111 Lecture 11: More on List Recursion
Document Summary
Implementing map using cons (define (map p lst) (if (empty lst) empty) (cons (p (first lst)) (map p (rest lst))))) Recurses to compute the rest of the list. Empty (cons figure out a new element to add (proc args to build the rest of the list )))) We know this because once we get back to the recursive call, there is still work to b done ---> we have to use cons. Accumulated result (proc args for rest of list . (cons . new element to add . Growing of the list happens before the recursive call. We locally define something, then use it by: (help lst empty) at the bottom of the procedure. Empty = accumulator to be ch case they. If the list is empty, return value we have accumulated. Otherwise, call help on a shorter list (help (rest lst-rem) lst-rem is the remainder of th.