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

0 votes
in Records and Types by

Hi

I would like to create methods of a record without defining a protocol:
(defprotocol ComponentProtocol
(view [x])
(render [x]))

(defrecord Component [...]
ComponentProtocol
(view [x] ...)
(render[x] ...))

=> instead define record as follows:

(defrecord Component [...]
(view [x] ...)
(render [x] ...))

regards
-Taoufik

1 Answer

0 votes
by

As far as I know this isn't possible. You always have to implement an interface or protocol. If you don't want a protocol, you can create an interface with definterface.

by
That’s correct and is part of the design intent to steer you away from OO style “arbitrary API”. We already have a mechanism for making standalone methods - functions.
by
https://clojure.org/reference/datatypes Is the relevant doc explaining the motivations here
...