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)) (setv comment (HyString))
(if (= (type (first bodies)) HyString) (if (= (type (first bodies)) HyString)
(setv [comment bodies] (head-tail bodies))) (setv [comment bodies] (head-tail bodies)))
(setv ret `(do)) (+ '(do (import [hy.contrib.multi [MultiDispatch]])) (lfor
(.append ret '(import [hy.contrib.multi [MultiDispatch]])) [let-binds #* body] bodies
(for [body bodies] `(with-decorator MultiDispatch (defn ~name ~let-binds ~comment ~@body)))))
(setv [let-binds body] (head-tail body))
(.append ret
`(with-decorator MultiDispatch (defn ~name ~let-binds ~comment ~@body))))
ret)
(do (do
(setv [lambda-list body] (head-tail bodies)) (setv [lambda-list body] (head-tail bodies))
`(setv ~name (fn* ~lambda-list ~@body))))) `(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. returns an OrderedDict mapping headers to sublists.
Arguments without a header are under None. Arguments without a header are under None.
" "
(setv headers '[&optional &rest &kwonly &kwargs] (setv headers ['&optional '&rest '&kwonly '&kwargs]
sections (OrderedDict [(, None [])]) sections (OrderedDict [(, None [])])
header None) header None)
(for [arg form] (for [arg form]
@ -169,7 +169,7 @@ Arguments without a header are under None.
#{}))))) #{})))))
(defn handle-args-list [self] (defn handle-args-list [self]
(setv protected #{} (setv protected #{}
argslist `[]) argslist [])
(for [[header section] (-> self (.tail) first lambda-list .items)] (for [[header section] (-> self (.tail) first lambda-list .items)]
(if header (.append argslist header)) (if header (.append argslist header))
(cond [(in header [None '&rest '&kwargs]) (cond [(in header [None '&rest '&kwargs])