-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheval-tests.scm
112 lines (92 loc) · 1.54 KB
/
eval-tests.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
(test
(hole? '_.0)
#t)
(test
(hole? 'a)
#f)
(test
(my-eval
'(letrec ((foo
(lambda (n)
(if (= n 0)
1
_.0))))
(foo 0))
)
1)
(test
(my-eval
'(letrec ((foo
(lambda (n)
(if (= n 0)
1
_.0))))
(foo 10))
)
HOLE)
(test
(lambda-params '(lambda (x) body))
'(x))
(test
(lambda-body '(lambda (x) body))
'body)
(test
(my-eval '2)
2)
(test
(my-eval 2)
2)
(test
(my-eval '(+ 1 2))
3)
(test
(my-eval '(+ 1 (+ 2 3)))
6)
(test
(my-eval '(quote (hello world)))
'(hello world))
(test
(my-eval '((lambda (x) (+ x 1)) 2))
3)
(test
(my-eval '(if #t 1 2))
1)
(test
(my-eval '(assert (= (+ 1 2) 3)))
#t)
(test
(my-eval '(let ((x (+ 1 2)) (y (+ 3 4))) (+ x y)))
10)
(define ycombinator-term
'(lambda (fun)
((lambda (F)
(F F))
(lambda (F)
(fun (lambda (x) ((F F) x)))))))
(define factorial-term
'(lambda (factorial)
(lambda (n)
(if (= n 0)
1
(* n (factorial (- n 1)))))))
(test
(my-eval
(list (list ycombinator-term factorial-term) 6)
)
720)
(test
(my-eval
'(letrec ((factorial
(lambda (n)
(if (= n 0)
1
(* n (factorial (- n 1)))))))
(factorial 6))
)
720)
(test
(define-lambda '(define f (lambda (x) x)))
'(lambda (x) x))
(test
(define-lambda '(define (f x) x))
'(lambda (x) x))