> > Have you actually looked at the data structure implementations in > ClojureScript? The work is done. It's all protocols. > Hi David,
I just have. This is a nice work. There is a lot of repetitions though. For example: - IEquiv (-equiv [coll other] (equiv-sequential coll other)) - IHash (-hash [coll] (caching-hash coll hash-coll __hash)) (where caching-hash has to be a macro) - ICounted (-count [coll] count) - ILookup (-lookup [coll k] (-nth coll k nil)) (-lookup [coll k not-found] (-nth coll k not-found)) All these appears multiple times in the file, each time for the same underlying reason. Each occurance is a missed opportunity for code reuse. (There must be other repetitions, that just those I found in a 2 minutes search) Add 4 more types of Vectors and you will have 4 more copies of those. And, I am not sure of that, but I think that in Clojurescript, the extend family has the same performance characteristics than deftype. Which makes things easier. Of course, deftype is sufficient for writing any class system, but you have to repeat yourself. And that is annoying. I don't advocate inheritance, which I think is a wrong answer to a good question, but someone needs to think of a way to reuse code in deftype. If you look at the big picture, multimethods are wonderful, protocols are great, reify is amazing, the extend family is top notch, but deftype lacks far behind in expressivity. (It is a very low-level construct, which the other are not.) And if deftype is in the language is because it is sometimes useful. And if it is useful, it should be made a pleasure to use as is the rest of the language. My first idea would be to add a macro (deftype-something body) that executes (or reduces) body at compile time in order to build a data structure containing the fields and the protocol/interface instances to be included in the resulting deftype. And then build a small library of functions to build classes. (extend-protocol, add-field, an so on...). It would solve one of the main problem of deftype: neither FP nor macros can help you much to build a type. Best, Nicolas. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en