exercise-15.scm (2712B)
1 (define-library (sicp tests chapter-3 exercise-15) 2 (import (scheme base)) 3 (import (srfi :64)) 4 5 (begin 6 (test-begin "chapter-3-exercise-15") 7 8 (define (set-to-wow! x) 9 (set-car! (car x) 'wow) 10 x) 11 12 (define x (list 'a 'b)) 13 (define z1 (cons x x)) 14 (define z2 (cons (list 'a 'b) 15 (list 'a 'b))) 16 ;; +---+---+ 17 ;; z1: --> | * | * | 18 ;; +-|-+-|-+ 19 ;; V V 20 ;; +---+---+ +---+---+ 21 ;; x: --> | * | *-+---->| * | / | 22 ;; +-|-+---+ +-|-+---+ 23 ;; V V 24 ;; +---+ +---+ 25 ;; | a | | b | 26 ;; +---+ +---+ 27 ;; 28 ;; +---+---+ +---+---+ +---+---+ 29 ;; z2: --> | * | * +---->| * | *-+--->| * | / | 30 ;; +-|-+---+ +-|-+---+ +-|-+---+ 31 ;; | V V 32 ;; | +---+ +---+ 33 ;; | | a | | b | 34 ;; | +---+ +---+ 35 ;; | ^ ^ 36 ;; | | | 37 ;; | +-|-+---+ +-|-+---+ 38 ;; +---------->| * | *-+--->| * | / | 39 ;; +---+---+ +---+---+ 40 (test-equal '(a b) x) 41 (test-equal '((a b) a b) z1) 42 (test-equal '((a b) a b) z2) 43 44 (set-to-wow! z1) 45 (set-to-wow! z2) 46 ;; +---+---+ 47 ;; z1: --> | * | * | 48 ;; +-|-+-|-+ 49 ;; V V 50 ;; +---+---+ +---+---+ 51 ;; x: --> | * | *-+---->| * | / | 52 ;; +-|-+---+ +-|-+---+ 53 ;; V V 54 ;; +-----+ +---+ 55 ;; | wow | | b | 56 ;; +-----+ +---+ 57 ;; 58 ;; +---+---+ +---+---+ +---+---+ 59 ;; z2: --> | * | * +---->| * | *-+--->| * | / | 60 ;; +-|-+---+ +-|-+---+ +-|-+---+ 61 ;; | V V 62 ;; | +---+ +---+ 63 ;; | | a | | b | 64 ;; | +---+ +---+ 65 ;; | ^ 66 ;; | +-----+ | 67 ;; | | wow | | 68 ;; | +-----+ | 69 ;; | ^ | 70 ;; | | | 71 ;; | +-|-+---+ +-|-+---+ 72 ;; +---------->| * | *-+--->| * | / | 73 ;; +---+---+ +---+---+ 74 (test-equal '(wow b) x) 75 (test-equal '((wow b) wow b) z1) 76 (test-equal '((wow b) a b) z2) 77 78 (test-end "chapter-3-exercise-15")))