This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
/
repl.lisp
67 lines (66 loc) 路 2.57 KB
/
repl.lisp
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
((lambda (eval environment)
((lambda (loop)
(loop loop null))
(lambda (loop^ repl)
(loop^ loop^ (write (eval eval (read) environment))))))
(lambda (eval^ exp env)
(if (symbol? exp)
((lambda (asq)
(asq asq exp env))
(lambda (asq^ e1 env1)
(if (null? env1)
null
(if (eq? e1 (car (car env1)))
(car (cdr (car env1)))
(asq^ asq^ e1 (cdr env1))))))
(if (symbol? (car exp))
(if (eq? (car exp) (quote quote))
(car (cdr exp))
(if (eq? (car exp) (quote if))
(if (eval^ eval^ (car (cdr exp)) env)
(eval^ eval^ (car (cdr (cdr exp))) env)
(eval^ eval^ (car (cdr (cdr (cdr exp)))) env))
(if (eq? (car exp) (quote lambda))
exp
((lambda (evlist)
(if (eq? (car exp) (quote apply))
((lambda (fn args)
(apply fn args))
(eval^ eval^ (car (cdr exp)) env)
(eval^ eval^ (car (cdr (cdr exp))) env))
((lambda (fn)
(if (pair? fn)
(eval^ eval^ (cons fn (cdr exp)) env)
(apply fn (evlist evlist (cdr exp) env))))
(eval^ eval^ (car exp) env))))
(lambda (evlist^ e1 evargs)
(if (null? e1)
null
(cons (eval^ eval^ (car e1) env)
(evlist^ evlist^ (cdr e1) evargs))))))))
(if (eq? (car (car exp)) (quote lambda))
((lambda (env1)
(eval^ eval^ (car (cdr (cdr (car exp)))) env1))
((lambda (bind names values extenv)
(bind bind names values extenv))
(lambda (bind^ names values extenv)
(if (null? names)
extenv
(cons (cons (car names) (cons (eval^ eval^ (car values) env) null))
(bind^ bind^ (cdr names) (cdr values) extenv))))
(car (cdr (car exp)))
(cdr exp)
env))
null))))
(cons (cons (quote hello) (cons (quote carl) null))
(cons (cons (quote car) (cons car null))
(cons (cons (quote cdr) (cons cdr null))
(cons (cons (quote cons) (cons cons null))
(cons (cons (quote eq?) (cons eq? null))
(cons (cons (quote pair?) (cons pair? null))
(cons (cons (quote symbol?) (cons symbol? null))
(cons (cons (quote null) (cons null null))
(cons (cons (quote null?) (cons null? null))
(cons (cons (quote read) (cons read null))
(cons (cons (quote write) (cons write null)) null)))))))))))
)