Ex 2.23
map そのものじゃ、ダメなのかな?
(map (lambda (x) (newline) (display x)) (list 1 2 3)) 1 2 3 ; value 22: (#!unspecific #!unspecific #!unspecific)
ってんで題意を満たしている、気がする。
一方、
(define (for-each f xs) (if (null? xs) true ((f (car xs)) (for-each f (cdr xs)))))
というのはダメみたいだ。 else 節の、値が二つある、というのが原因か?
ああそうか、 accumulate みたく、値を「まとめる」演算を入れてやればいいんだ。 true に対して次々に引数を評価していく特殊形式を使ってやればいい。そう、 and だ。
(define (for-each f xs) (if (null? xs) true (and (f (car xs)) (for-each f (cdr xs)))))