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

让人想犯罪 __ 提交于 2020-01-11 05:19:13

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/23147764/what-was-the-reasoning-behind-clojurescript-not-needing-clojures-defstruct

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!