University of Washington • CSE583 • D. Notkin
©
2000
42
map
: apply a function to each
element of a list, returning a list
l
(map square ‘(3 4 5))
®
(9 16 25)
l
(map is-positive? ‘(3 -4 5))
®
(#t #f #t)
l
(defun (map fn x)
(if (null? x) ()
(cons (fn (car x))
(map fn (cdr x)))))
l
l
The resulting list is always of the same length as
the list to which
map
is applied