-
Notifications
You must be signed in to change notification settings - Fork 0
/
interp.scm
41 lines (34 loc) · 1015 Bytes
/
interp.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
(load "pmatch.scm")
(load "types.scm")
(load "synext.scm")
(type-alias 'Envr '(list (pair any any)))
(type-alias 'Expr '(list any))
;; typed selectors
(defn (: value (-> Expr any)) (exp)
(car (cdr exp)))
(defn (: type (-> Expr any)) (exp)
(car exp))
;; untyped selectors
(define operator cadr)
(define operand caddr)
(define param cadr)
(define body caddr)
(defn (: teval (-> (* Expr Envr) any)) (exp env)
(if (eq? (type exp) 'var)
(cdr (assoc (value exp) env))
(if (eq? (type exp) 'int)
(value exp)
(if (eq? (type exp) 'app)
(tapply
(teval (operator exp) env)
(teval (operand exp) env))
(if (eq? (type exp) 'lam)
(listof (: any)
(param exp) (body exp) env)
(listof (: any)))))))
;; untyped apply
(define (tapply f arg)
(pmatch f
((,x ,body ,env)
(teval body (cons (cons x arg) env)))
(else (error "attempting to apply non-function"))))