Blob


1 ;; Exercise 2.23. The procedure for-each is similar to map. It takes as arguments a procedure and a list of elements. However, rather than forming a list of the results, for-each just applies the procedure to each of the elements in turn, from left to right. The values returned by applying the procedure to the elements are not used at all -- for-each is used with procedures that perform an action, such as printing. For example,
3 (define (for-each proc items)
4 (if (null? items)
5 #t
6 (and (proc (car items))
7 (for-each proc (cdr items)))))
9 (define (test-case actual expected)
10 (load-option 'format)
11 (newline)
12 (format #t "Actual: ~A Expected: ~A" actual expected))
14 (for-each (lambda (x) (newline) (display x))
15 (list 57 321 88))
16 (newline)
17 (display 57)
18 (newline)
19 (display 321)
20 (newline)
21 (display 88)