Clojure:休息与下一个 [英] Clojure: rest vs. next

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

问题描述

我很难理解 Clojure 中 restnext 之间的区别.官方网站关于懒惰的页面表明偏好可能应该是使用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 更严格,因为它需要评估lazy cons的结构才能知道是返回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 的结果之前不需要评估任何内容.换句话说,restnext 更懒惰.

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:休息与下一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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