Use nonlocal
instead of a singleton list
This commit is contained in:
parent
4a40ff3d7e
commit
dce0e10f3f
@ -45,22 +45,24 @@
|
|||||||
(setv module (or (and module-name
|
(setv module (or (and module-name
|
||||||
(import-module module-name))
|
(import-module module-name))
|
||||||
(calling-module))
|
(calling-module))
|
||||||
quote-level [0]
|
quote-level 0
|
||||||
ast-compiler (HyASTCompiler module)) ; TODO: make nonlocal after dropping Python2
|
ast-compiler (HyASTCompiler module)) ; TODO: make nonlocal after dropping Python2
|
||||||
(defn traverse [form]
|
(defn traverse [form]
|
||||||
(walk expand identity form))
|
(walk expand identity form))
|
||||||
(defn expand [form]
|
(defn expand [form]
|
||||||
|
(nonlocal quote-level)
|
||||||
;; manages quote levels
|
;; manages quote levels
|
||||||
(defn +quote [&optional [x 1]]
|
(defn +quote [&optional [x 1]]
|
||||||
|
(nonlocal quote-level)
|
||||||
(setv head (first form))
|
(setv head (first form))
|
||||||
(+= (get quote-level 0) x)
|
(+= quote-level x)
|
||||||
(when (neg? (get quote-level 0))
|
(when (neg? quote-level)
|
||||||
(raise (TypeError "unquote outside of quasiquote")))
|
(raise (TypeError "unquote outside of quasiquote")))
|
||||||
(setv res (traverse (cut form 1)))
|
(setv res (traverse (cut form 1)))
|
||||||
(-= (get quote-level 0) x)
|
(-= quote-level x)
|
||||||
`(~head ~@res))
|
`(~head ~@res))
|
||||||
(if (call? form)
|
(if (call? form)
|
||||||
(cond [(get quote-level 0)
|
(cond [quote-level
|
||||||
(cond [(in (first form) '[unquote unquote-splice])
|
(cond [(in (first form) '[unquote unquote-splice])
|
||||||
(+quote -1)]
|
(+quote -1)]
|
||||||
[(= (first form) 'quasiquote) (+quote)]
|
[(= (first form) 'quasiquote) (+quote)]
|
||||||
|
Loading…
Reference in New Issue
Block a user