Hi Brave and True folks
I’m still not super clear on destructuring. I’m on the macros chapter doing ex. 3. I have the 1-arity version working. But the single vector version doesn’t work, and I’m confused about how the destructuring syntax should work.
(defmacro create-attrs-fn
([fnname attribute]
`(def ~fnname (comp ~attribute :attributes)))
([[fnname attribute & remaining]]
(do (create-attrs-fn fnname attribute
(create-attrs-fn remaining)))))
because of not understanding destructuring I can’t figure out what’s the arity of my functions.
For example:
(defn mytest [fnname attribute] "nothing")
(:arglists (meta #'mytest))
;=> ([fnname attribute])
The above looks like 2-arity. However, what’s this:
(defn mytest [[fnname attribute & remaining] v] "nothing")
(:arglists (meta #'mytest))
;=> ([[fnname attribute & remaining] v])
I’m using this from SO:
(defn arg-count [f]
(let [m (first (.getDeclaredMethods (class f)))
p (.getParameterTypes m)]
(alength p)))
Let’s see if that helps.Hmm… I don’t get what’s up from my error messages.
(defn mytest [[fnname attribute & remaining]] "nothing")
(arg-count mytest)
; => 1
So, why do I get an error that I can’t call my macro with 1-arity with this definition?
(defmacro create-attrs-fn
([[fnname attribute & remaining]]
(do (create-attrs-fn fnname attribute)
(create-attrs-fn ~remaining)))
([fnname attribute]
`(def ~fnname (comp ~attribute :attributes))))
:man-shrugging: