独家或红宝石的关键字? [英] Keyword for exclusive or in ruby?

查看:27
本文介绍了独家或红宝石的关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ruby 是否有一个纯英文关键字来表示异或,就像它们有and"和or"一样?如果不是,这是因为独占还是不允许评估捷径?

Does Ruby have a plain-English keyword for exclusive or, like they have "and" and "or"? If not, is this because exclusive or doesn't allow evaluation short-cutting?

推荐答案

首先,我认为短路不能合理地应用于 XOR:无论第一个操作数的值如何,都需要检查第二个操作数.

Firstly, I don't think shortcircuiting can sensibly apply to XOR: whatever the value of the first operand, the second needs to be examined.

其次,and, &&, or and ||在所有情况下都使用短路;单词"和符号"版本之间的唯一区别是优先级.我相信 andor 的存在是为了提供与 perl 在

Secondly, and, &&, or and || use shortcircuiting in all cases; the only difference between the "word" and "symbol" versions is precedence. I believe that and and or are present to provide the same function as perl has in lines like

process_without_error or die

我认为没有 xor 命名函数的原因可能是在这种情况下低优先级运算符没有意义,而且它已经是一个足够令人困惑的情况了!

I think the reason for not having a xor named function is probably that there's no point in a low-precedence operator in this case and that it's already a confusing enough situation!

这篇关于独家或红宝石的关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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