Question

defstruct is not supported in ClojureScript - it would appear to be by design. Now it may be that this is effectively a deprecated part of the Clojure language, and the designers of ClojureScript were just hoping everyone had moved on. (But this is my speculation).

My question is: What was the reasoning behind ClojureScript not needing Clojure's defstruct?

Was it helpful?

Solution

defstruct is effectively deprecated in the language, in favor of defrecord. We are supposed to move on in (JVM-based) Clojure, so I would expect Clojurescript to be the same. See the following:

Clojure: data structures: "Note: Most uses of StructMaps would now be better served by records."

ClojureDocs: defstruct comment by steveminer: "Structs are obsolete. Use records instead. See defrecord."

The forthcoming The Joy of Clojure, 2nd ed. (prerelease V9 edition) by Fogus and Houser says "With the advent of defrecord, the need for structs has been nearly eliminated, and therefore structs aren’t covered in this book." (p. 322)

Also note that Programming Clojure, 2nd ed. by Halloway and Bedra covers defrecord but not defstruct (although there are some passing mentions of structures--maybe accidentally left from the 1st ed.).

I guess all the cool people are using defrecord these days. :-)

Alex Miller's answer to "Where should I use defrecord in clojure?" has a nice discussion of advantages (and disadvantages) of defrecord, although he's not, primarily, comparing it with defstruct.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top