EECS 111 Lecture Notes - Lecture 7: Substitution Model

49 views4 pages

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.

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