Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What was the reasoning behind ClojureScript not needing Clojure's defstruct?

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?

like image 207
hawkeye Avatar asked Apr 18 '14 05:04

hawkeye


1 Answers

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.

like image 188
Mars Avatar answered Oct 29 '22 17:10

Mars