问题
If I'm implementing some data structure in Clojure using deftype
, how should I decide which of the core Clojure interfaces to implement?
I was unable to find a comprehensive guide to the various Clojure interfaces; in fact, the only relevant piece of information I was able to find was this question, which is very limited in scope.
What I'm looking for is a list of each of the core Clojure interfaces, with a brief description of what it is and when you should implement it (or if you should even implement it at all!), as well as a list of all the common functions in clojure.core
that use it. A description or diagram of the inheritance tree of all these interfaces would also be helpful.
回答1:
i can not answer all your questions but I usually start from clojure atlas http://www.clojureatlas.com/ to find which interfaces to implement.
回答2:
The excellent book Clojure Applied by Ben Vandgrift and Alex Miller provides detailed information on this exact topic in "Chapter 2. Collect and Organize Your Data", under "Building Custom Collections". A visual diagram of interfaces in clojure.lang
is provided on page 39.
来源:https://stackoverflow.com/questions/33504959/how-should-i-properly-implement-the-core-clojure-interfaces