exercise-33.scm (973B)
1 (define-library (sicp solutions chapter-2 exercise-33) 2 (import (scheme base)) 3 (import (sicp utils)) 4 (export map-2.33 append-2.33 length-2.33) 5 6 (begin 7 (define (map-2.33 p sequence) 8 (accumulate (lambda (x y) 9 (cons (p x) 10 y)) 11 '() 12 sequence)) 13 14 (define (append-2.33 seq1 seq2) 15 (accumulate cons 16 seq2 17 seq1)) 18 19 (define (length-2.33 sequence) 20 (accumulate (lambda (x y) (+ 1 y)) 21 0 22 sequence)) 23 24 25 (define (map p sequence) 26 (accumulate (lambda (x y) 27 (cons (p x) 28 y)) 29 '() 30 sequence)) 31 32 (define (append seq1 seq2) 33 (accumulate cons 34 seq2 35 seq1)) 36 37 (define (length sequence) 38 (accumulate (lambda (x y) (+ 1 y)) 39 0 40 sequence))))