Clojure:rest和next [英] Clojure: rest vs. next

查看:179
本文介绍了Clojure:rest和next的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解Clojure中的 rest next 之间的区别。 官方网站的懒惰页面表示偏好应该是使用 rest ,但它并没有真正解释清楚两者之间的区别。

I'm having a hard time understanding the difference between rest and next in Clojure. The official site's page on laziness indicates that the preference should probably be to use rest, but it doesn't really explain clearly the difference between the two. Can anybody provide some insight?

推荐答案

您链接的页面描述为 next 比($的新行为) rest 更严格,因为它需要评估延迟缺点的结构以知道是否返回 nil 或者seq。

As the page you linked described, next is stricter than (the new behaviour of) rest because it needs to evaluate the structure of the lazy cons to know whether to return nil or a seq.

rest 另一方面总是返回一个seq,以评估,直到您实际使用 rest 的结果。换句话说, rest next 更懒惰。

rest on the other hand always returns a seq, so nothing needs to be evaluated until you actually use the result of rest. In other words, rest is more lazy than next.

这篇关于Clojure:rest和next的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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