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