EECS 111 Lecture 11: More on List Recursion

55 views4 pages

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents