你不假思索第一反应回答: "Either A or B" 翻译成开发中的逻辑关系是?

2017-01-26 18:27:57 +08:00
 KentY

今天被同事问到,然后,我答错了... :-( 被告知答案后..服气.

8891 次点击
所在节点    程序员
57 条回复
KentY
2017-01-26 19:49:39 +08:00
@ho121 在你说的这个 context 里, 肯定是非红即黑, 但是 either A or B 有可能判定 4 种情况的结果, 就是 AB 分别为 TT, TF, FF, FT, A xor B 可以根据这四种输入来做出判断.

这个问题的由来是, 我在公司做了个东西, 简单说, 就是个用户的输入判断, 有 4 个输入框, 分两组(A B) (C D), 要求是要么 AB 都填, 要么 CD 都填, 当然全空或者穿插缺项, E.g. (AC or BD) 是要提示错误.

然后同事在使用中发现, 如果 ABCD 全填了, 我就处理 AB 被填的那个逻辑去了, 他觉得应该是提示错误信息, 我说这不是个 or 的关系吗, 他说, it is not an "or" relation, instead it is an "either-or" relation. 我说, 对啊, 那不也是 logical OR 吗? 他说 are you sure? it is XOR.. 我仔细一想, 人家说的对啊......
xuqd
2017-01-26 19:54:28 +08:00
Either[A,B]
Mes0
2017-01-26 20:37:16 +08:00
异或吧
circsqua
2017-01-26 20:39:23 +08:00
异或
laoyuan
2017-01-26 20:49:04 +08:00
要么 A 要么 B
yangff
2017-01-26 20:57:04 +08:00
这种情况说 Exactly one 或者 One and Only One 比较合适吧

至于 either 并不能很准确的表示二者之一这个意思……
loading
2017-01-26 20:57:16 +08:00
这个其实是英语题吧……
yangff
2017-01-26 21:01:50 +08:00
Determiner[edit]
either
Each of two. [from 9th c.]  [quotations ▼]
One or the other of two. [from 14th c.]  [quotations ▼]
(coordinating) Used before two or more **not necessarily exclusive possibilities separated by "or"** or sometimes by a comma.  [quotations ▼]

https://en.wiktionary.org/wiki/either
IgniteWhite
2017-01-26 21:05:24 +08:00
@loading 其实是英语题,本来说啥都对的啊,后来这个问题被问得多了,连我们 CA 老师上课时候都讲这个逗我们,现在在贵圈 either 的意思就缩小成这样了……
realpg
2017-01-26 21:28:15 +08:00
上技术社区考了一个英语题……
hx1997
2017-01-26 21:53:02 +08:00
https://en.wikipedia.org/wiki/Either/Or_(disambiguation)

Either/Or and related terms may also refer to:

Logical disjunction, the logical meaning of "either ... or ... or both"
Exclusive or, the logical meaning of "either ... or ... but not both"

可以指逻辑析取(逻辑或),也可以指异或。这个其实有歧义。
codelegant
2017-01-26 22:45:54 +08:00
这是一道英语题。
ZE3kr
2017-01-26 22:58:57 +08:00
平常所说的的 or ,中文的或,大多数情况下都是编程语言中的 xor ,这点很坑。
ZE3kr
2017-01-26 23:00:58 +08:00
@ynyounuo 这个其实是集合的运算符,不过其实都差不多
edimetia3d
2017-01-26 23:13:29 +08:00
各位英语捉急啊,英语中 either 的逻辑与 both 意义等价. Either A or B 的逻辑意义是 A 和 B 必须都为真.若任何一个为假,则不能用 either
所以是 A and B
IgniteWhite
2017-01-26 23:16:43 +08:00
@edimetia3d 喷了,哥们你是在钓鱼对吧
PythonAnswer
2017-01-26 23:45:40 +08:00
@edimetia3d 我觉得 either 和 both 是不同的。

either A or B == both A and B?
IgniteWhite
2017-01-26 23:56:05 +08:00
@PythonAnswer 你被钓鱼了。。。
edimetia3d
2017-01-26 23:57:42 +08:00
@IgniteWhite
@PythonAnswer
开玩笑,各位这么认真,语言上的东西没必要这么较真啊.

从语法的理论上讲,这样分析应该是没错的.
陈述句举例: Either this apple or that apple is bad == Both apples are bad.

实际应用中最正确的回答是"随语境".
因为 either or 可以用在陈述句中使用,也可以用在选择句中,而有的选择句中强调必须择其一,有的则不限制必须择其一.

就像"i++i+i++i+++i"的结果一样,答案是随编译器而定的
IgniteWhite
2017-01-27 00:04:14 +08:00
@edimetia3d 哥你不是在开玩笑的样子……

你在说 and 和 or 没区别,视编译器而定,是吗

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/337049

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX