Fork me on GitHub

November’s meetup is a remote presentation on spec by Stuart Halloway


Reading Alex Miller’s wonderful post on Clojure collections this AM: He says: "Ideally traits would be defined as Clojure protocols, but their implementation dates back to the earliest days of Clojure, well before protocols existed and as such they are defined by Java interfaces.” A little poking led me to the happy discovery that ClojureScript, by dint of being developed post-Clojure-1.2 I suppose, and having the benefit of Protocols, implements the collection traits as protocols yay!


related question: I notice from the Sequences documentation, this extremely clarifying blurb: "Many of the functions in the seq library take one or more collections, call seq on them, and then operate on the resulting seq. In other words, many of these functions take collections but operate on their seqs.” I wonder why the implementors chose to (unconditionally) call seq on a (collection) argument instead of adding a function (of ^ISeq) to the multimethod (in each case) and using dispatch instead. Wouldn’t dispatch have a potential performance advantage?


Apparently (and happily) the whole notion of “interfaces” (as opposed to “protocols”) is entirely absent from ClojureScript. A clue is here: “`gen-class`, gen-interface, etc. are unnecessary and unimplemented in ClojureScript"


And so, circling back to my original question about the seq call versus multimethod dispatch on ^ISeq (an interface type)—that wouldn’t work in ClojureScript I suppose.


But wait, David Nolen fixed “Support Types & Protocols as Type Hints” in ClojureScript: So apparently, multimethod dispatch on ^ISeq (the protocol) would work in ClojureScript.