| 1 |
|
| 2 |
(add-tests-with-string-output "set!" |
| 3 |
[(let ([x 12]) |
| 4 |
(set! x 13) |
| 5 |
x) => "13\n"] |
| 6 |
[(let ([x 12]) |
| 7 |
(set! x (fxadd1 x)) |
| 8 |
x) => "13\n"] |
| 9 |
[(let ([x 12]) |
| 10 |
(let ([x #f]) (set! x 14)) |
| 11 |
x) => "12\n"] |
| 12 |
[(let ([x 12]) |
| 13 |
(let ([y (let ([x #f]) (set! x 14))]) |
| 14 |
x)) => "12\n"] |
| 15 |
[(let ([f #f]) |
| 16 |
(let ([g (lambda () f)]) |
| 17 |
(set! f 10) |
| 18 |
(g))) => "10\n"] |
| 19 |
[(let ([f (lambda (x) |
| 20 |
(set! x (fxadd1 x)) |
| 21 |
x)]) |
| 22 |
(f 12)) => "13\n"] |
| 23 |
[(let ([x 10]) |
| 24 |
(let ([f (lambda (x) |
| 25 |
(set! x (fxadd1 x)) |
| 26 |
x)]) |
| 27 |
(cons x (f x)))) => "(10 . 11)\n"] |
| 28 |
[(let ([t #f]) |
| 29 |
(let ([locative |
| 30 |
(cons |
| 31 |
(lambda () t) |
| 32 |
(lambda (n) (set! t n)))]) |
| 33 |
((cdr locative) 17) |
| 34 |
((car locative)))) => "17\n"] |
| 35 |
[(let ([locative |
| 36 |
(let ([t #f]) |
| 37 |
(cons |
| 38 |
(lambda () t) |
| 39 |
(lambda (n) (set! t n))))]) |
| 40 |
((cdr locative) 17) |
| 41 |
((car locative))) => "17\n"] |
| 42 |
[(let ([make-counter |
| 43 |
(lambda () |
| 44 |
(let ([counter -1]) |
| 45 |
(lambda () |
| 46 |
(set! counter (fxadd1 counter)) |
| 47 |
counter)))]) |
| 48 |
(let ([c0 (make-counter)] |
| 49 |
[c1 (make-counter)]) |
| 50 |
(c0) |
| 51 |
(cons (c0) (c1)))) => "(1 . 0)\n"] |
| 52 |
[(let ([fact #f]) |
| 53 |
(set! fact (lambda (n) |
| 54 |
(if (fxzero? n) |
| 55 |
1 |
| 56 |
(fx* n (fact (fxsub1 n)))))) |
| 57 |
(fact 5)) => "120\n"] |
| 58 |
[(let ([fact #f]) |
| 59 |
((begin |
| 60 |
(set! fact (lambda (n) |
| 61 |
(if (fxzero? n) |
| 62 |
1 |
| 63 |
(fx* n (fact (fxsub1 n)))))) |
| 64 |
fact) |
| 65 |
5)) => "120\n"] |
| 66 |
|
| 67 |
) |
| 68 |
|