6.001 Recitation #7 – Feb 26, 2003
RI: Konrad Tollmar
Program methodology
3. Let
Use let to write a procedure that compute
a = 1 + xy; b = 1 - y; f(x,y) = a2x + by + ab
x
=> (())
y
=> (1 2 3)
z
=> (1 (2 3) ((4)))
w
=> (1 2 3 4 5)
(map
(lambda (x) (cons x nil)) y)
(map
inc w)
(filter odd? w)
(map
inc (filter odd? w))
(filter
odd? (map inc w))
(accumulate
+ 0 (map inc (filter odd? w)))
5. What are the types of these procedures?
1. length
2. list-ref
3.
map
4. filter 5. accumulate
Write a function comp that takes two arguments a and b and returns a function, that when called with #t returns a and when called with #f returns b.