Skip to content

Commit

Permalink
support (global) in let
Browse files Browse the repository at this point in the history
  • Loading branch information
gilch committed Sep 18, 2017
1 parent ba898aa commit 20b4342
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 3 additions & 1 deletion hy/contrib/walk.hy
Original file line number Diff line number Diff line change
Expand Up @@ -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 `[])
Expand Down Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions tests/native_tests/contrib/walk.hy
Original file line number Diff line number Diff line change
Expand Up @@ -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"))))

0 comments on commit 20b4342

Please sign in to comment.