Fix let rebind bug.

This commit is contained in:
gilch 2018-06-27 22:37:40 -06:00
parent 4b0e318997
commit 8c79015b40
2 changed files with 13 additions and 2 deletions

View File

@ -305,6 +305,7 @@ as can nested let forms.
(macro-error bindings "let bindings must be paired"))
(setv g!let (gensym 'let)
replacements (OrderedDict)
keys []
values [])
(defn expander [symbol]
(.get replacements symbol symbol))
@ -315,10 +316,11 @@ as can nested let forms.
(macro-error k "binding target may not contain a dot")))
(.append values (symbolexpand (macroexpand-all v &name)
expander))
(assoc replacements k `(get ~g!let ~(name k))))
(.append keys `(get ~g!let ~(name k)))
(assoc replacements k (last keys)))
`(do
(setv ~g!let {}
~@(interleave (.values replacements) values))
~@(interleave keys values))
~@(symbolexpand (macroexpand-all body &name)
expander)))

View File

@ -329,3 +329,12 @@
3))
(assert (= b 3))
(assert (= c 3))))
(defn test-let-rebind []
(let [x "foo"
y "bar"
x (+ x y)
y (+ y x)
x (+ x x)]
(assert (= x "foobarfoobar"))
(assert (= y "barfoobar"))))