map
a common idiom
- make a new list by doing something to each element in a list
- eg, add1, square-each
- write a procedure that expresses this pattern
(define (map proc p) (if (null? p) nil (cons (proc (car p)) (map proc (cdr p)))))
sample uses of map
- (define (add1 p) (map inc p))
- (define (square-each p) (map square p))
- (define (addx p x) (map (lambda (i) (+ i x)) p)