user1311390
user1311390

Reputation:

Clojure: defprotocol, default implementaion, not inlined

Edit

This question makes no sense because I'm an idiot and misread the Clojure documentation.

What I have:

I have something like this:

(defprotocol Foo "doc" [foo bar]
  (Foo-bark [foo])
  (Foo-meow [foo])
  (Foo-other [foo]
     ... long
     multi
     line
     inline
     implementation))

What I would prefer:

(defprotocol Foo "doc" [foo bar]
  (Foo-bark [foo])
  (Foo-mewo [foo])
  (Foo-other [foo]))

(define Foo-other [foo]
   .. long
   multi
    line
   implementation)

Question

Is the above possible? If not, what is the closest I can get to it?

Upvotes: 2

Views: 442

Answers (1)

Joost Diepenmaat
Joost Diepenmaat

Reputation: 17773

defprotocol can't be used to provide implementations for its functions/methods. You need to use deftype or reify or extend / extend-type (or drop down to classes to do that. For your use-case, you can use extend to refer to earlier-defined functions to implement a protocol.

Upvotes: 4

Related Questions