简体   繁体   English

为什么运算符在 CShell 中是右结合的,而在 C 中是左结合的?

[英]Why are operators right associative in CShell that are left associative in C?

Following up from my previous question , why is CShell so different from C?我之前的问题之后,为什么 CShell 与 C 如此不同?

  • 4 - 3 + 1 = 2 in C. C 中的 4 - 3 + 1 = 2。
  • 4 - 3 + 1 = 0 in CShell. CShell 中的 4 - 3 + 1 = 0。

Any ideas?有任何想法吗?

Generally the traditional notation is left to right (left associative) in human papers.通常,传统符号在人类论文中是从左到右(左结合)。 So for humans (which used this notation long before c, csh or even any notion of computers):所以对于人类(早在 c、csh 甚至任何计算机概念之前就使用这种表示法):

4 - 3 + 1 = (4 - 3) + 1 = 1 + 1 = 2

Why?为什么? I guess that the best answer is because.我想最好的答案是因为。 It's the same as with driving left or right side of road.这与在道路左侧或右侧行驶相同。 It really doesn't matter which side as long as everyone uses the same.只要每个人都使用相同的东西,哪一边真的不重要。

IMHO the csh is wrong as it is counter-intuitive.恕我直言,csh 是错误的,因为它违反直觉。 Possibly it was an error (they wanted left associative but coded wrongly) and become legacy as other things already depeneded on this.可能这是一个错误(他们想要左关联但编码错误)并成为遗产,因为其他事情已经依赖于此。

Different people wrote the products, and they had different views of how to handle the calculations.不同的人编写产品,他们对如何处理计算有不同的看法。 And since the C Shell was written second, I think they're at fault for not following the lead of the nominal parent language.由于 C Shell 是第二个写的,我认为他们没有遵循名义母语的领导是错误的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM