简体   繁体   English

优先选择 rest 而不是 car 和 cdr 的 lisp 如何处理 cdaddr 之类的组合?

[英]How do lisps that prefer first and rest to car and cdr approach combinations like cdaddr?

One of the great schisms in the Lisp community is if we should have car and cdr or first and rest . Lisp 社区中最大的分歧之一是我们是否应该拥有carcdrfirstrest One of the benefits of the traditional car and cdr is that we can combine them to produce pronoucible functions like cdaddr .传统carcdr的好处之一是我们可以将它们结合起来产生像cdaddr这样的发音功能。 How do Lisps that do not use car and cdr , such as Clojure, typically form combinations like this with first and rest ?不使用carcdr的 Lisps,例如 Clojure,通常如何与firstrest形成这样的组合? Is there any consensus?有没有共识?

Clojure, at any rate, simply has no need for caddaadr and friends, because nobody builds data structures out of just cons cells. Clojure,无论如何,根本不需要 caddaadr 和朋友,因为没有人仅仅从 cons 单元构建数据结构。 The language does have combinations of any two of first and next , named ffirst , fnext , nnext , and nfirst , which were added very early on I suppose because it was assumed we'd want something like cadr, but I never see them used in real life.该语言确实有firstnext中任意两个的组合,命名为ffirstfnextnnextnfirst ,我想这些是很早就添加的,因为假设我们想要像 cadr 这样的东西,但我从来没有看到它们用于现实生活。 Instead destructuring is used quite often.相反,经常使用解构。

On the rare occasions where you need to reach deeply into a structure built of nested sequences, destructuring often still produces readable code but also writing it out longhand is no great burden.在极少数情况下,您需要深入了解由嵌套序列构建的结构,解构通常仍会产生可读的代码,但手写出来也不是什么大负担。 It's also a good hint to you that maybe you should abstract thing a bit more rather than working with so many layers of primitive combinators directly.这也是对您的一个很好的暗示,也许您应该更多地抽象事物,而不是直接使用如此多的原始组合器层。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM