I am trying to implement a protocol with a record in a clojure program I'm writing. the error I'm getting is "Unsupported binding form".
(defprotocol query-rows
(query-text [table])
(trans-cols [table rows])
(set-max [table] [table id]))
(defrecord Submissions [data max-id]
query-rows
(query-text [table]
(gen-query-text "SubmissionId" "Valid" "Submission"))
(trans-cols [table rows]
(let
[trans-data
(->>
rows
(trans-col #(if % 1 0) :valid :valid_count)
(trans-col #(if % 0 1) :valid :non_valid_count)
(trans-col format-sql-date :createdon :date))]
(assoc table :data trans-data)))
(set-max
([table]
(when-let [id (gen-get-max "SubmissionAgg2")]
(assoc table :max-id id)))
([table id] (assoc table :max-id id))))
The "set-max" function is what's throwing the error. I have a feeling I'm trying to use multiple arity incorrectly. Does anyone know what I'm doing wrong?
You have correctly diagnosed the problem. You'll need to follow the examples at http://clojure.org/protocols and define the multiple arities of your set-max method separately in the body of defrecord.
...
(set-max [table] ...)
(set-max [table id] ...)
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With