EECS 111 Lecture Notes - Lecture 7: Substitution Model
Document Summary
Summing a list (sum-list (list 1 2 3)) Simplest sum-list: (define (sum-list-2 list) (+ (first list) (second list))) Not using any primitive iterators like map or filter. Summing a 3-element list (define (sum-list-3 list) (+ (first list) (second list) (third list))) (define (sum-list-3 list) (+ (first list) (sum-list-2 (rest list)))) Summing a 5-element lsit (define (sum-list-5 list) (+ (first list) (sum-list-4 (rest list)))) If the list is empty, return 0; if not, add the first element of the list to the rest. How do we write fold? e is no recursion here yet. Start (proc (first list) (myfoldr proc start) (rest list))))) Recursion is about writing procedures that call themselves. Break it down into simpler versions of itself then call itself on simpler versions. Double-quotes let you type a string as a constant in your code. "this is a test string" ---> means a string whose characters are t, h, i, s, space, i, s, et.