Require that defhelper arglist has two elements
one for the map and one for varargs Add & to metadata arglists, make them correct
This commit is contained in:
parent
e0072efbdc
commit
f22cae3278
1 changed files with 9 additions and 4 deletions
|
|
@ -15,9 +15,14 @@
|
||||||
|
|
||||||
#?(:clj
|
#?(:clj
|
||||||
(defmacro defhelper [helper arglist & more]
|
(defmacro defhelper [helper arglist & more]
|
||||||
(let [kw (keyword (name helper))]
|
(when-not (vector? arglist)
|
||||||
|
(throw (IllegalArgumentException. "arglist must be a vector")))
|
||||||
|
(when-not (= (count arglist) 2)
|
||||||
|
(throw (IllegalArgumentException. "arglist must have two entries, map and varargs")))
|
||||||
|
(let [kw (keyword (name helper))
|
||||||
|
[m-arg varargs] arglist]
|
||||||
`(do
|
`(do
|
||||||
(defmethod build-clause ~kw ~(into ['_] arglist) ~@more)
|
(defmethod build-clause ~kw ~['_ m-arg varargs] ~@more)
|
||||||
(defn ~helper [& args#]
|
(defn ~helper [& args#]
|
||||||
(let [[m# args#] (if (plain-map? (first args#))
|
(let [[m# args#] (if (plain-map? (first args#))
|
||||||
[(first args#) (rest args#)]
|
[(first args#) (rest args#)]
|
||||||
|
|
@ -30,8 +35,8 @@
|
||||||
(var ~helper)
|
(var ~helper)
|
||||||
assoc
|
assoc
|
||||||
:arglists
|
:arglists
|
||||||
'(~(into [] (rest arglist))
|
'(~['& varargs]
|
||||||
~(into [(first arglist)] (rest arglist))))))))
|
~[m-arg '& varargs]))))))
|
||||||
|
|
||||||
(defn collify [x]
|
(defn collify [x]
|
||||||
(if (coll? x) x [x]))
|
(if (coll? x) x [x]))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue