Fork me on GitHub
#clojure-dev
<
2018-09-10
>
hiredman01:09:58

maybe a wiki page somewhere cataloging the regular var linkage case vs. all the exceptions to var linkage would be a good useful

andy.fingerhut02:09:22

I may be about 1/3 of the way there...

andy.fingerhut02:09:57

Will send out a link if I get something for people to critique

andy.fingerhut06:09:03

OK, I have used the nodisassemble library to look at the JVM bytecode of a normal Clojure function call that derefs through a Var, and compared that to a defprotocol method call. The Clojure compiler recognizes that when the Var in function position of a call like (a-var-name ...) is a protocol method, it emits different byte code that is roughly: "if the first arg implements the Java interface created when defprotocol was done, do invokeinterface on that Java interface, without regard to the value of the Clojure Var. Otherwise, do a normal Clojure function call that indirects through the current value of the Clojure Var created for the protocol method." There is a 1-item cache that is actually checked before seeing if the arg implements the Java interface, that skips the first if, too.

andy.fingerhut06:09:27

In short, from the JVM byte code, it makes sense that some but not all protocol method calls ignore the value of the protocol method Vars.