flâneur — a map of the web's best reading

CSC 151 - Higher-order design, recursive and other

eikmeier.sites.grinnell.edu · 3,482 words · saved by 1 readers

After writing many recursive functions you may have noticed general patterns in the code you wrote. For example, calculating the length of a list: That should look similar to summing the elements of a list: Which, with a little bit of eye-contortion, is similar to appending lists: In all three cases: In the spirit of functions-as-abstractions, can we write a function that captures this generic behavior? This line of investigation leads us back to the big three list functions, map, filter, and reduce! We motivate the design of higher-order recursive functions by examining their implementation and discuss their limitations in more detail. Recall that (map fun lst) returns a new list in which each element is the corresponding element of lst transformed by unary function fun. For example, we can (map increment nums) to increment all the elements of nums by 1 or we can (map zero? nums) to turn every element of l into a boolean denoting whether that element was zero. How can we implement map

CSC 151 - Higher-order design, recursive and other Higher-order design, recursive and other Due Wednesday, 29 October 2025 --> Summary In this reading, we apply recursive design to higher-order procedures, revisiting the big three list functions: map, filter, and reduce. After writing many recursive functions you may have noticed general patterns in the code you wrote. For example, calculating the length of a list: (define length (lambda (lst) (match lst [null 0] [(cons head tail) (+ 1 (length tail))]))) That should look similar to summing the elements of a list: (define sum (lambda (lst) (mat

Explore this link on the map →

saved by

related reading