Why am I getting an "Unsupported binding form" error when implementing a protocol in clojure?

I am trying to implement a protocol with an entry in the clojure program that I am writing. The error I get is "Unsupported form of binding".

    (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 throws an error. It feels like I'm trying to misuse a few things. Does anyone know what I'm doing wrong?

+4
source share
1 answer

You correctly diagnosed the problem. You will need to follow the http://clojure.org/protocols examples and define several phenomena of your set-max method separately in the defrecord body.

...
(set-max [table] ...)
(set-max [table id] ...)
...
+4

Source: https://habr.com/ru/post/1523747/


All Articles