This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-04
Channels
- # announcements (5)
- # beginners (124)
- # boot (43)
- # braveandtrue (8)
- # calva (1)
- # cider (44)
- # cljs-dev (1)
- # clojure (188)
- # clojure-canada (3)
- # clojure-germany (1)
- # clojure-italy (5)
- # clojure-nl (13)
- # clojure-russia (1)
- # clojure-spec (14)
- # clojure-uk (42)
- # clojurescript (94)
- # core-async (5)
- # cursive (5)
- # datomic (45)
- # duct (3)
- # emacs (6)
- # figwheel-main (93)
- # fulcro (22)
- # graphql (3)
- # hyperfiddle (1)
- # leiningen (3)
- # off-topic (1)
- # pedestal (1)
- # play-clj (1)
- # portkey (1)
- # re-frame (17)
- # reagent (71)
- # remote-jobs (2)
- # rum (3)
- # shadow-cljs (45)
- # spacemacs (17)
- # specter (18)
- # tools-deps (27)
- # unrepl (1)
- # vim (3)
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.
(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))))