Working extend-rec?
This commit is contained in:
parent
4cad341a5d
commit
b723750417
@ -71,24 +71,17 @@
|
|||||||
|
|
||||||
; 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 : Env] [sym : Symbol] [exp : Exp])
|
||||||
(local [(define self (extend env sym exp)]
|
(local [(define self (extend env sym (funV sym exp env)))]
|
||||||
(begin
|
(type-case (Optionof (Boxof Value)) (hash-ref self sym)
|
||||||
(set! (funV-nv self) env)
|
[(none) self]
|
||||||
(hash-set self sym (box(interp exp self))))))
|
[(some b) (begin
|
||||||
|
(set-box! b (funV sym exp self))
|
||||||
|
self)])))
|
||||||
|
|
||||||
#;(let* ([exp (parse `{lam x {f 0}})]
|
(let* ([exp (parse `{lam x {f 0}})]
|
||||||
[env (extend-rec mt-env 'f exp)]
|
[env (extend-rec mt-env 'f exp)]
|
||||||
[fun (lookup 'f env)])
|
[fun (lookup 'f env)])
|
||||||
(begin
|
(test (funV-nv fun) env))
|
||||||
(display exp)
|
|
||||||
(display "\n")
|
|
||||||
(display env)
|
|
||||||
(display "\n")
|
|
||||||
(display fun)
|
|
||||||
(display "\n")
|
|
||||||
(display (funV-nv fun))
|
|
||||||
(display "\n")
|
|
||||||
(test (funV-nv fun) env)))
|
|
||||||
|
|
||||||
(interp : (Exp Env -> Value))
|
(interp : (Exp Env -> Value))
|
||||||
(define (interp e nv)
|
(define (interp e nv)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user