为什么应该(每个?字符串?[])产生真? [英] Why should (every? string? []) yield true?

查看:18
本文介绍了为什么应该(每个?字符串?[])产生真?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看every 的源代码? 清楚为什么

(every? string? []) => true

这是因为 every? 是递归实现的,并且使用 (nil? (seq coll)) 来结束递归.但是,我的问题是,这种行为有什么意义?只是被那个绊倒了.

This is because every? is implemented recursively and uses (nil? (seq coll)) to end recursion. But, my question is, what sense does this behaviour make? Just tripped over that.

我已经使用

(and (seq x) (every? string? x))

推荐答案

因为它的功能与 forall-量词相同.也就是说,它最初被假定为真,并且谓词的每次应用都是试图证明它是假的.存在量词(在 Clojure 中,由于不一致而被称为 some 而不是 any?)以相反的方式工作 - 它假设为假,并且谓词的每个应用都是尝试证明是真的.

Because it functions the same as the forall-quantifier. That is, it is initially assumed true and each application of the predicate is an attempt to prove it false. The existential quantifier (which is called some rather than any? in Clojure for inconsistencies sake) works the opposite way - it assumes false and each application of the predicate is an attempt to prove it true.

换言之,某事对所有人都为真总是正确的,而某事对所有人都为真的总是错误的.

In other words, it's always true that something is true for all of none, and it's always false that something is true for some of none.

这篇关于为什么应该(每个?字符串?[])产生真?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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