The Clojure compiler checks to see if protocols and types implement protocols?

Is the Clojure compiler designed to verify that a record or a type that says it creates a protocol actually implements the methods listed in it?

I try it now and so far, it does not look like.

+1
clojure clojure-protocol
source share
1 answer

A record can implement a protocol without implementing any of its methods:

(defprotocol Structure (weight [this]) (balanced? [this])) (defrecord Mobile [] Structure ) 

... accepted.

If you try to use a nonexistent method:

 (balanced? (Mobile.)) ;java.lang.AbstractMethodError: user.Mobile.balanced_QMARK_()Ljava/lang/Object; 

As usual, type errors are detected at runtime.

+1
source share

All Articles