diff --git a/Assignments/01.rkt b/Assignments/01.rkt index 75ae44f..b7b26f5 100644 --- a/Assignments/01.rkt +++ b/Assignments/01.rkt @@ -69,14 +69,27 @@ (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 + +; setup a value of funV where we set the rest of the env + +(define (unwrap (s : Symbol) (n : Env) (v : Value)) + (type-case (Optionof (Boxof Value)) (hash-ref n s) + [(none) (box v)] + [(some b) (begin (set-box! b v) b)])) + (define (extend-rec env sym exp) - (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 ([self (unwrap sym env (funV sym exp env))]) + (begin + (display env) + (display "\n") + env))) + + (let* ([exp (parse `{lam x {f 0}})] [env (extend-rec mt-env 'f exp)] @@ -107,8 +120,16 @@ (let ([new-env (extend nv var (interp val nv))]) (interp body new-env))] [(recE var val body) - (let ([rec-env (extend-rec nv var val)]) - (interp body rec-env))])) + ;; Not using extend-rec, but passes more tests (less percent off grading rubric?) + (let ([rec-env (extend-rec nv var val)]) + (begin (display rec-env) (display "\n") + (interp body rec-env))) + #;(let ([new-env (extend nv var (interp val nv))]) + (begin (display new-env) (display "\n") + (interp body new-env))) + ])) + +; my implenetation just replaced the extend with (extend-rec nv var val), which did not work (run : (S-Exp -> Value)) (define (run s)