|
34 | 34 | (check-equal? (run '(unbox 8)) 'err) |
35 | 35 |
|
36 | 36 | ;; Iniquity tests |
37 | | - #| |
38 | 37 | (check-equal? (run |
39 | | - '(begin (define (f x) x) |
40 | | - (f 5))) |
41 | | - 5) |
| 38 | + '(begin (define (f x) x) |
| 39 | + (f 5))) |
| 40 | + 5) |
42 | 41 |
|
43 | 42 | (check-equal? (run |
44 | | - '(begin (define (tri x) |
45 | | - (if (zero? x) |
46 | | - 0 |
47 | | - (+ x (tri (sub1 x))))) |
48 | | - (tri 9))) |
| 43 | + '(begin (define (tri x) |
| 44 | + (if (zero? x) |
| 45 | + 0 |
| 46 | + (+ x (tri (sub1 x))))) |
| 47 | + (tri 9))) |
49 | 48 | 45) |
50 | 49 |
|
51 | 50 | (check-equal? (run |
52 | | - '(begin (define (even? x) |
53 | | - (if (zero? x) |
54 | | - #t |
55 | | - (odd? (sub1 x)))) |
56 | | - (define (odd? x) |
57 | | - (if (zero? x) |
58 | | - #f |
59 | | - (even? (sub1 x)))) |
60 | | - (even? 101))) |
61 | | - #f) |
| 51 | + '(begin (define (even? x) |
| 52 | + (if (zero? x) |
| 53 | + #t |
| 54 | + (odd? (sub1 x)))) |
| 55 | + (define (odd? x) |
| 56 | + (if (zero? x) |
| 57 | + #f |
| 58 | + (even? (sub1 x)))) |
| 59 | + (even? 101))) |
| 60 | + #f) |
62 | 61 |
|
63 | 62 | (check-equal? (run |
64 | | - '(begin (define (map-add1 xs) |
65 | | - (if (empty? xs) |
66 | | - '() |
67 | | - (cons (add1 (car xs)) |
68 | | - (map-add1 (cdr xs))))) |
69 | | - (map-add1 (cons 1 (cons 2 (cons 3 '())))))) |
70 | | - '(2 3 4)) |
71 | | - |# |
| 63 | + '(begin (define (map-add1 xs) |
| 64 | + (if (empty? xs) |
| 65 | + '() |
| 66 | + (cons (add1 (car xs)) |
| 67 | + (map-add1 (cdr xs))))) |
| 68 | + (map-add1 (cons 1 (cons 2 (cons 3 '())))))) |
| 69 | + '(2 3 4)) |
| 70 | + |
72 | 71 |
|
73 | 72 | ;; Loot examples |
74 | 73 |
|
|
86 | 85 | 1 |
87 | 86 | (+ n (tri (sub1 n))))))) |
88 | 87 | 10)) |
89 | | - 56)) |
| 88 | + 56) |
| 89 | + |
| 90 | + |
| 91 | + (check-equal? (run |
| 92 | + '(begin (define (map-add1 xs) |
| 93 | + (if (empty? xs) |
| 94 | + '() |
| 95 | + (cons (add1 (car xs)) |
| 96 | + (map-add1 (cdr xs))))) |
| 97 | + (map-add1 (cons 1 (cons 2 (cons 3 '())))))) |
| 98 | + '(2 3 4)) |
| 99 | + (check-equal? (run '(begin (define (f x) x) |
| 100 | + f)) |
| 101 | + 'procedure) |
| 102 | + (check-equal? (run '(begin (define (f x) x) |
| 103 | + (f 5))) |
| 104 | + 5) |
| 105 | + |
| 106 | + (check-equal? (run '((λ (f) (f 0)) (λ (x) (add1 x)))) 1) |
| 107 | + (check-equal? (run '((λ (f) (f (f 0))) (λ (x) (add1 x)))) 2) |
| 108 | + (check-equal? (run '((let ((y 8)) (car (cons (λ (x) y) '()))) 2)) 8) |
| 109 | + (check-equal? (run '(let ((y 8)) ((car (cons (λ (x) y) '())) 2))) 8) |
| 110 | + |
| 111 | + (check-equal? |
| 112 | + (run |
| 113 | + '(begin (define (map f ls) |
| 114 | + (if (empty? ls) |
| 115 | + '() |
| 116 | + (cons (f (car ls)) (map f (cdr ls))))) |
| 117 | + |
| 118 | + (map (λ (f) (f 0)) |
| 119 | + (cons (λ (x) (add1 x)) |
| 120 | + (cons (λ (x) (sub1 x)) |
| 121 | + '()))))) |
| 122 | + '(1 -1)) |
| 123 | + |
| 124 | + (check-equal? |
| 125 | + (run |
| 126 | + '(begin (define (map f ls) |
| 127 | + (letrec ((mapper (λ (ls) |
| 128 | + (if (empty? ls) |
| 129 | + '() |
| 130 | + (cons (f (car ls)) (mapper (cdr ls))))))) |
| 131 | + (mapper ls))) |
| 132 | + (map (λ (f) (f 0)) |
| 133 | + (cons (λ (x) (add1 x)) |
| 134 | + (cons (λ (x) (sub1 x)) |
| 135 | + '()))))) |
| 136 | + '(1 -1)) |
| 137 | + |
| 138 | + (check-equal? |
| 139 | + (run |
| 140 | + '(begin (define (map f ls) |
| 141 | + (begin (define (mapper ls) |
| 142 | + (if (empty? ls) |
| 143 | + '() |
| 144 | + (cons (f (car ls)) (mapper (cdr ls))))) |
| 145 | + (mapper ls))) |
| 146 | + (map (λ (f) (f 0)) |
| 147 | + (cons (λ (x) (add1 x)) |
| 148 | + (cons (λ (x) (sub1 x)) |
| 149 | + '()))))) |
| 150 | + '(1 -1))) |
| 151 | + |
| 152 | +(test-suite |
| 153 | + (λ (e) |
| 154 | + (match (interp e) |
| 155 | + [(? procedure?) 'procedure] |
| 156 | + [v v]))) |
90 | 157 |
|
91 | | -(test-suite interp) |
92 | | -(test-suite defun:interp) |
| 158 | +(test-suite |
| 159 | + (λ (e) |
| 160 | + (match (defun:interp e) |
| 161 | + [(? defun:function?) 'procedure] |
| 162 | + [v v]))) |
0 commit comments