Sean Geoffrey Pietz
Sean Geoffrey Pietz

Reputation: 1140

Why am I getting "Unsupported binding form" error when implementing protocol in 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?

Upvotes: 5

Views: 4010

Answers (1)

A. Webb
A. Webb

Reputation: 26446

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] ...)
...

Upvotes: 5

Related Questions