syntax - 为什么 "||"是 or 的符号?

标签 syntax operators history bitwise-or logical-or

关闭。这个问题是off-topic .它目前不接受答案。












想改进这个问题? Update the question所以它是on-topic对于堆栈溢出。

9年前关闭。




Improve this question




我知道||代表逻辑运算“或”,但我很好奇是否有人知道选择该符号的历史。仅仅是因为它恰好是键盘上未使用的符号吗?

最佳答案

单竖线“|”的起点表示析取的“或”。

来自 ASCII character history :

It has been conjectured that the vertical line character was introduced to the area of computing with the Backus-Naur Form metalanguage for describing programming languages. It was also taken into use in APL in early 1960's and incorporated into PL/I at about the same time as the OR operator and, doubled, as the concatenation operator.



John Warner Backus (1924 年 12 月 3 日 - 2007 年 3 月 17 日)是美国计算机科学家。他领导的团队发明了第一个广泛使用的高级编程语言 (FORTRAN),并且是巴科斯-瑙尔形式 (BNF) 的发明者,这是一种几乎普遍用于定义形式语言语法的符号。他还研究了函数级编程并帮助推广它。

作为 IBM 的一名编程语言设计师,他提出了“元语言公式”来描述新的编程语言 IAL(今天称为 ALGOL 58)的语法,使用 BNF 表示法。

在巴科斯-瑙尔形式中,表达式由符号序列和/或用“|”分隔的序列组成,表示选择,整体是左边符号的可能替换。
<personal-name> ::= <name> | <initial>
在 ALGOL 58 规范中,Backus 最初并没有使用垂直线;他使用了“或”这个词,上面有一条线(以及逻辑符号OR symbol)。 Peter Naur ,为 ALGOL 60 做出贡献的丹麦计算机科学家将几个符号修改为可以在标准键盘上键入的符号。他的变化之一是增加了垂直线。 (来源:“History of Programming Languages”,Richard L. Wexelblat)

然而,即使在 ALGOL 60 规范之后,也有很多 OR symbol 的示例。符号仍与 ALGOL 一起使用。事实上,在 1961 年,ASCII 字符集添加了反斜杠,因此 ALGOL 的逻辑运算符可以用斜杠输入,如下所示:\/ /\这些符号可以在 60 年代中期推出的 IBM 2741 键盘上找到:

IBM Keyboard

但是有明确的证据表明,Naur 在 ALGOL 60 中添加了垂直线。在 1964 年发表的一篇文章中,(Knuth D.,“Backus Normal Form vs. Backus Naur Form”致编辑的信,ACM 通讯,第 7 卷( 1964). pp. 735-736, available here ),Donald Knuth 认为,由于 Naur 的贡献,“巴科斯范式”应该被称为“巴科斯·瑙尔式”。他提到的贡献之一是添加了垂直线作为或运算符。

这是 1964 年文章的一部分的图片。请注意右侧的项目符号 (iv)。

enter image description here

文章继续描述 Naur 对语义变化负责,这是他对 1960 年 Algol 报告的编辑职责的一部分:

enter image description here

双竖线“||”的起源

The Development of the C Language , Dennis M. Ritchie 描述了为什么要添加双竖线运算符:

Rapid changes continued after the language had been named, for example the introduction of the && and || operators. In BCPL and B, the evaluation of expressions depends on context: within if and other conditional statements that compare an expression's value with zero, these languages place a special interpretation on the and (&) and or (|) operators. In ordinary contexts, they operate bitwise, but in the B statement

if (e1 & e2) ...

the compiler must evaluate e1 and if it is non-zero, evaluate e2, and if it too is non-zero, elaborate the statement dependent on the if. The requirement descends recursively on & and | operators within e1 and e2. The short-circuit semantics of the Boolean operators in such `truth-value' context seemed desirable, but the overloading of the operators was difficult to explain and use. At the suggestion of Alan Snyder, I introduced the && and || operators to make the mechanism more explicit.



(感谢 Richard Brown 对本节的研究)。

关于syntax - 为什么 "||"是 or 的符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15056896/

相关文章:

git - 如何取消删除之前在 git 历史记录中删除的文件?

php - 有没有一种简写方法可以将一组变量分配给 php 中数组的每个值?

c++ - 不同的函数指针语法作为另一个函数的参数

syntax - 如何在 RediSearch 中编写包含和排除标签的查询?

PHP PDO 插入 MySQL 错误 SQL 语法

python - 重新定义 __and__ 运算符

javascript - 我可以在 JS 中中断 try - catch 而不抛出异常吗?

c# - 如何重载 C# 中的方括号运算符?

history - 为什么一开始就不是代码 "managed"?

ajax - 如何在 UpdatePanel 中保存历史记录?