Working extend-rec?

This commit is contained in:
Isaac Shoebottom 2025-02-11 02:37:31 -04:00
parent 4cad341a5d
commit b723750417

View File

@ -71,24 +71,17 @@
; 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])
(local [(define self (extend env sym exp)]
(begin
(set! (funV-nv self) env)
(hash-set self sym (box(interp exp self))))))
(local [(define self (extend env sym (funV sym exp env)))]
(type-case (Optionof (Boxof Value)) (hash-ref self sym)
[(none) 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)]
[fun (lookup 'f env)])
(begin
(display exp)
(display "\n")
(display env)
(display "\n")
(display fun)
(display "\n")
(display (funV-nv fun))
(display "\n")
(test (funV-nv fun) env)))
(test (funV-nv fun) env))
(interp : (Exp Env -> Value))
(define (interp e nv)