Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Clojure by

Hello! I have struggled to understand how to implement a multi-arity protocol method with a record, so I’d like to suggest an improvement to the defrecord docstring to make this clearer. I am thinking about this change (new is the last paragraph):

(methodname [args*] body)

The argument and return types can be hinted on the arg and
methodname symbols. If not supplied, they will be inferred, so type
hints should be reserved for disambiguation.

For multi-arity methods, add a separate (methodname ...) entry
for each one.*

1 Answer

0 votes

Isn't this implied by the stated syntax, given that it does not state a multi-arity syntax?

I don't think it is, given that `defprotocol` uses a different syntax and `fn`/`defn`/`letfn` all use another different syntax. The current documentation could also imply that you can't implement multi-arity functions (as it's not explicitly stated to support it).
I am sure that are folks that see that implied and are happy with that. But as you can see from my suggestion, I am not one of those sufficiently smart :-) and would have preferred more explicit info