为什么Clojure之父说Scheme的true/false被打破了?
在此视频中,Rich Hickey 向 Lisp 程序员介绍了 Clojure。
时间 01:10:42,他在 Clojure/Common Lisp/Scheme/Java 中谈到了 nil/false/end-of-sequence/'()。他说:“计有真有假,但都破了。”
我不明白他为什么这么说,为什么他认为它“坏了”?
In this video, Rich Hickey introduced Clojure for Lisp programmers.
At time 01:10:42, he talked about nil/false/end-of-sequence/'() among Clojure/Common Lisp/Scheme/Java. He said: "Scheme has true and false, but they are broken."
I don't understand why he said that and why does he consider it's "broken"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我觉得你宁愿从马嘴里看到它,所以这里有一个选择摘录自 a消息丰富的帖子:
该消息中的链接也很有价值,尽管第二个可能有点诗意。
It strikes me you'd rather see it from the horse's mouth, so here's a choice extract from a message Rich posted:
The links in that message are also worthwhile, though the second one may be a bit poetic.
从您发布的图表中,我认为这是因为与图表中的所有其他语言不同,Scheme 使用
nil
或false
以外的内容作为end-of-seq
。由于'()
是非#f
,因此它在条件中将是真值,但在序列结束检查中充当假值。From the chart you posted I'd assume it's because Scheme unlike all the other languages in the chart uses something other than
nil
orfalse
forend-of-seq
. Since'()
isnon-#f
it would be a truthy value in a conditional, but acts as a falsy value for end of sequence checks.在Scheme中,任何值(除了#f,它是False)都可以在条件测试中用作True。更多信息此处。
更新
忘记这个答案吧,因为这对于 Clojure 当然是一样的。我不喜欢所有非假值的隐式真理,例如在 (println (if 1 "true" "false")) 中。就我个人而言,我认为这已经被打破了,但里奇可能正在考虑别的事情。
In Scheme any value (apart from #f which is False) can be used as True in a conditional test. More info here.
Update
Forget this answer, since it's the same for Clojure of course. I don't like this implicit truth for all values that are not false, for example in (println (if 1 "true" "false")). Personally I would consider that broken but Rich is probably thinking of something else.