Avoid mutating HyLists in hy.contrib

This commit is contained in:
Kodi Arfer 2019-08-02 17:05:28 -04:00
parent 9ddb3b1031
commit 95ad5a01c8
2 changed files with 5 additions and 9 deletions

View File

@ -84,13 +84,9 @@
(setv comment (HyString))
(if (= (type (first bodies)) HyString)
(setv [comment bodies] (head-tail bodies)))
(setv ret `(do))
(.append ret '(import [hy.contrib.multi [MultiDispatch]]))
(for [body bodies]
(setv [let-binds body] (head-tail body))
(.append ret
`(with-decorator MultiDispatch (defn ~name ~let-binds ~comment ~@body))))
ret)
(+ '(do (import [hy.contrib.multi [MultiDispatch]])) (lfor
[let-binds #* body] bodies
`(with-decorator MultiDispatch (defn ~name ~let-binds ~comment ~@body)))))
(do
(setv [lambda-list body] (head-tail bodies))
`(setv ~name (fn* ~lambda-list ~@body)))))

View File

@ -89,7 +89,7 @@ splits a fn argument list into sections based on &-headers.
returns an OrderedDict mapping headers to sublists.
Arguments without a header are under None.
"
(setv headers '[&optional &rest &kwonly &kwargs]
(setv headers ['&optional '&rest '&kwonly '&kwargs]
sections (OrderedDict [(, None [])])
header None)
(for [arg form]
@ -169,7 +169,7 @@ Arguments without a header are under None.
#{})))))
(defn handle-args-list [self]
(setv protected #{}
argslist `[])
argslist [])
(for [[header section] (-> self (.tail) first lambda-list .items)]
(if header (.append argslist header))
(cond [(in header [None '&rest '&kwargs])