Overview
I would certainly appreciate suggestions of other extra credit activities (preferably via email).
Can you talk a bit more about problem 6?
Consider the following procedures
(define square-all
(lambda (lst)
(if (null? lst)
null
(cons (sqr (car lst)) (square-all (cdr lst))))))
(define double-all
(lambda (lst)
(if (null? lst)
null
(cons (* 2 (car lst)) (double-all (cdr lst))))))
We see a common form
(define something-all
(lambda (lst something)
(if (null? lst)
null
(cons (something (car lst)) (something-all (cdr lst) something)))))
We can redefine in terms of the common form
(define double-all
(lambda (lst)
(something-all lst (section * <> 2))))
Let’s look at three other procedures
(define sum
(lambda (lst)
(if (null? lst)
0
(+ (car lst) (sum (cdr lst))))))
(define select-odd
(lambda (lst)
(if (null? list)
null
(if (odd? (car lst))
(cons (car lst)
(select-odd (cdr lst)))
(select-odd (cdr lst))))))
Identify the common part
(define recursive-fun
(lambda (lst base-value combine)
(if (null? lst)
base-value
(combine (car lst) (recursive-fun (cdr lst) base-value combine)))))
Redefine
(define sum
(lambda (lst)
(recursive-fun lst 0 +)))
(define select-odd
(lambda (lst)
(recursive-fun lst null
(lambda (val lst2)
(if (odd? val)
(cons val lst2)
lst2)))))