ClojureScript 不需要 Clojure 的 defstruct 背后的原因是什么? [英] What was the reasoning behind ClojureScript not needing Clojure's defstruct?

查看:15
本文介绍了ClojureScript 不需要 Clojure 的 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 is 在语言中被有效弃用,支持 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 steveminer 的评论:结构已过时.改用记录. 请参阅取消记录."

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

即将发布的Clojure 的乐趣,第二版.Fogus 和 Houser 的(预发布 V9 版)说随着 defrecord 的出现,几乎不需要结构体,因此本书不涉及结构体."(第 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆