support (global) in let

This commit is contained in:
gilch 2017-09-18 14:44:24 -06:00
parent ba898aa8d8
commit 20b4342d40
2 changed files with 20 additions and 3 deletions

View File

@ -170,7 +170,6 @@ as can nested let forms.
(setv head (first form))
(setv tail (cut form 1))
(cond [(in head '[fn fn*])
;; TODO: handle globals, locals
(setv body (cut tail 1)
protected #{}
fn-bindings `[])
@ -218,6 +217,9 @@ as can nested let forms.
form)))
identity
tail))]
[(= head 'global)
(.update protected-symbols (set tail))
form]
[(in head '[import quote]) form]
[(= head 'defclass)
;; don't expand the name of the class

View File

@ -293,6 +293,21 @@
(assert (= 2 (+count)))
(assert (= 42 (+count 40))))
;; TODO
;; test-let-global
(defn test-let-global []
(setv (get (globals)
'let-global)
"global")
(let [let-global 1]
(assert (= let-global 1))
(defn foo []
(assert (= let-global 1))
(global let-global)
(assert (= let-global "global"))
(setv let-global "mutated")
(assert (= let-global "mutated")))
(foo)
(assert (= let-global 1))
(assert (= (get (globals)
'let-global)
"mutated"))))