;; IN: list, a function ;; OUT: list ;; BEHAVIOR: destructively applies the function onto every element of the list ;; preserves original pointer (define (map! fn ls) (if (null? ls) '() (begin (set-car! ls (fn (car ls))) (map! fn (cdr ls)) ls))) ;; constructive version (define (map fn ls) (if (null? ls) '() (cons (fn (car ls)) (map fn (cdr ls)))))