???
This commit is contained in:
parent
b723750417
commit
6c5aa26491
@ -70,7 +70,7 @@
|
|||||||
(test/exn (lookup 'x mt-env) "not bound")
|
(test/exn (lookup 'x mt-env) "not bound")
|
||||||
|
|
||||||
; Needs to return new environment, with the boxed value containing the function, and a recursive reference to the same environment
|
; Needs to return new environment, with the boxed value containing the function, and a recursive reference to the same environment
|
||||||
(define (extend-rec [env : Env] [sym : Symbol] [exp : Exp])
|
(define (extend-rec env sym exp)
|
||||||
(local [(define self (extend env sym (funV sym exp env)))]
|
(local [(define self (extend env sym (funV sym exp env)))]
|
||||||
(type-case (Optionof (Boxof Value)) (hash-ref self sym)
|
(type-case (Optionof (Boxof Value)) (hash-ref self sym)
|
||||||
[(none) self]
|
[(none) self]
|
||||||
@ -96,7 +96,7 @@
|
|||||||
(if (equal? (numV 0) (interp c nv))
|
(if (equal? (numV 0) (interp c nv))
|
||||||
(interp z nv)
|
(interp z nv)
|
||||||
(interp nz nv))]
|
(interp nz nv))]
|
||||||
[(appE f a)
|
[(appE f a)
|
||||||
(let ([fv (interp f nv)]
|
(let ([fv (interp f nv)]
|
||||||
[av (interp a nv)])
|
[av (interp a nv)])
|
||||||
(type-case Value fv
|
(type-case Value fv
|
||||||
@ -104,11 +104,11 @@
|
|||||||
(interp b (extend f-env v av))] ;; changed
|
(interp b (extend f-env v av))] ;; changed
|
||||||
[else (error 'app "not a function")]))]
|
[else (error 'app "not a function")]))]
|
||||||
[(let1E var val body)
|
[(let1E var val body)
|
||||||
(let ([new-env (extend nv
|
(let ([new-env (extend nv var (interp val nv))])
|
||||||
var
|
|
||||||
(interp val nv))])
|
|
||||||
(interp body new-env))]
|
(interp body new-env))]
|
||||||
[(recE var val body) ....]))
|
[(recE var val body)
|
||||||
|
(let ([rec-env (extend-rec nv var val)])
|
||||||
|
(interp body rec-env))]))
|
||||||
|
|
||||||
(run : (S-Exp -> Value))
|
(run : (S-Exp -> Value))
|
||||||
(define (run s)
|
(define (run s)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user