-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinterp-helpers.scm
46 lines (41 loc) · 1.08 KB
/
interp-helpers.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
;;; helpers used in multiple interpreters
(define lookup
(lambda (x env)
(dmatch env
(() (error 'lookup "unbound variable"))
(((,y . ,v) . ,rest) (guard (eq? y x))
v)
(((,y . ,v) . ,rest) (guard (not (eq? y x)))
(lookup x rest)))))
(define not-in-env
(lambda (x env)
(dmatch env
(() #t)
(((,y . ,v) . ,rest) (guard (eq? y x)) #f)
(((,y . ,v) . ,rest) (guard (not (eq? y x)))
(not-in-env x rest)))))
(define lookupo
(lambda (x env t)
(fresh (y v rest)
(== `((,y . ,v) . ,rest) env)
(conde
((== y x) (== v t))
((=/= y x) (lookupo x rest t))))))
(define not-in-envo
(lambda (x env)
(conde
((== '() env))
((fresh (y v rest)
(== `((,y . ,v) . ,rest) env)
(=/= y x)
(not-in-envo x rest))))))
(define proper-listo
(lambda (exp env val)
(conde
((== '() exp)
(== '() val))
((fresh (a d v-a v-d)
(== `(,a . ,d) exp)
(== `(,v-a . ,v-d) val)
(eval-expo a env v-a)
(proper-listo d env v-d))))))