ClojureScript背后的原因是什么,不需要Clojure的defstruct? [英] What was the reasoning behind ClojureScript not needing Clojure's defstruct?
问题描述
defstruct
- 它似乎是设计的。现在可能是,这实际上是Clojure语言的一个弃用的部分,ClojureScript的设计师只是希望大家都移动。 (但这是我的猜测)。
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).
我的问题是: ClojureScript背后的推理不需要Clojure的defstruct?
推荐答案
defstruct 是在语言中有效地弃用,赞成
defrecord
。我们应该继续(基于JVM的)Clojure,所以我希望Clojurescript是一样的。查看以下内容:
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:数据结构:注意:现在,记录可以更好地为StructMaps提供服务。
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."
即将到来的Clojure的快乐,第2版。 (prerelease V9版)由Fogus和Houser说:随着 defrecord
的出现,对结构的需求几乎被消除了,因此结构体不在本书中。 。 (p。322)
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)
另请注意,编程Clojure 通过Halloway和Bedra涵盖 defrecord
但不是 defstruct
(虽然有一些经常提及的结构 - 第一次编辑)。
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.).
我想所有酷的人都在使用 defrecord
这些天。 : - )
I guess all the cool people are using defrecord
these days. :-)
Alex Miller的回答我应该在哪里在clojure中使用defrecord?对 defrecord
的优点(和缺点)进行了很好的讨论,尽管他不是,主要是与 defstruct
比较。
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
.
这篇关于ClojureScript背后的原因是什么,不需要Clojure的defstruct?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!