Skip to content

Commit

Permalink
Merge pull request #16 from alanzplus/master
Browse files Browse the repository at this point in the history
Fix let bindings evaluation issue
  • Loading branch information
chenyukang authored Nov 6, 2018
2 parents 14b39b6 + cf73629 commit 0406ff2
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions ch5/07.scm
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
(vars (list-of identifier?))
(vals (list-of expression?))
(body expression?)
(saved-env environment?)
(binding-eval-env environment?)
(body-eval-env environment?)
(saved-cont continuation?))
(if-test-cont
(exp2 expression?)
Expand Down Expand Up @@ -207,7 +208,7 @@
;;new stuff
(let-exp (vars exps body)
(value-of/k (car exps) env
(let-exp-cont vars (cdr exps) body env cont)))
(let-exp-cont vars (cdr exps) body env env cont)))

(if-exp (exp1 exp2 exp3)
(value-of/k exp1 env
Expand Down Expand Up @@ -259,16 +260,17 @@
(apply-procedure/k proc val saved-cont)))

;;new stuff
(let-exp-cont (vars exps body saved-env saved-cont)
(let-exp-cont (vars exps body binding-eval-env body-eval-env saved-cont)
(if (null? exps)
(value-of/k body (extend-env (car vars) val saved-env)
saved-cont)
(value-of/k (car exps)
(extend-env (car vars) val saved-env)
(let-exp-cont (cdr vars) (cdr exps) body
(extend-env (car vars) val saved-env)
saved-cont))))
)))
(value-of/k body (extend-env (car vars) val body-eval-env) saved-cont)
(value-of/k (car exps)
binding-eval-env
(let-exp-cont
(cdr vars)
(cdr exps)
body
binding-eval-env
(extend-env (car vars) val body-eval-env) saved-cont)))))

;; apply-procedure/k : Proc * ExpVal * Cont -> FinalAnswer
(define apply-procedure/k
Expand Down Expand Up @@ -299,6 +301,6 @@
(add-test! '(let-4 "let x = 30
in let x = -(x,1)
y = -(x,2)
in -(x, y)" 2))
in -(x, y)" 1))

(run-all)

0 comments on commit 0406ff2

Please sign in to comment.