Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jvm

clojure

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?

like image 969
Sean Geoffrey Pietz Avatar asked Jan 26 '14 00:01

Sean Geoffrey Pietz


1 Answers

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] ...)
...
like image 154
A. Webb Avatar answered Oct 29 '22 15:10

A. Webb