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

前端 未结 1 1563
故里飘歌
故里飘歌 2021-01-13 13:26

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,

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-13 14:06

    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.

    0 讨论(0)
提交回复
热议问题