I’ve been studying the implementation of ClojureScript and it is an absolutely wonderful experience. Thanks to all who are involved in this amazing experiment!
I have some concern about the implementation details of the immutable data structures which I'd like to see some discussion on. This is how I understand it, and please correct me if I’m wrong:
1. The data structures are implemented in pure clojure(script) using deftype and protocols.
2. deftype does not (and should not!) support static fields or methods.
3. What then, does forms like these mean (i.e. What are the semantics?) [1]:
- cljs.core.PersistentVector/EMPTY
- cljs.core.PersistentVector/fromArray
In the clojure world of java interop the above would be static fields and methods but there are no such things for neither deftype nor javascript so I would have guessed that these forms would be considered invalid. In fact, I’m amazed that it works at all, since they confuse the analyzer into thinking that there is a namespace called cljs.core.PersistentVector with a var named EMPTY.
What would be the alternative when implementing the clojure data structures using clojure itself? A good idea might be to look at the implementation of gvec[2]. In that implementation top level forms such as
(def EMPTY-NODE (VecNode. nil (object-array 32)))
are defined instead of using static fields.
Some discussion took place on IRC[3] earlier today. I think we should study the implementation of gvec and see how we could clean up the implementation of the clojurescript data structures. What do other people think?
Jonas