5

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?

1 Answer 1

5

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] ...)
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.