Project

General

Profile

Feature #15559

Logical XOR (^^) operator

Added by baweaver (Brandon Weaver) 27 days ago. Updated 25 days ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:91234]

Description

Currently we have bitwise & and logical &&, and bitwise | and logical ||. Would it be possible to have logical ^^ in addition to the bitwise ^ for XOR?

History

Updated by mrkn (Kenta Murata) 26 days ago

You can write expr1 ^^ expr2 as !expr1 != !expr2 in the current Ruby.
If both expr1 and expr2 are boolean, you can write expr1 != expr2.

I think ^^ can be useful for the case that both expr1 and expr2 are not boolean.
Have you ever write such conditional expressions?

Updated by mrkn (Kenta Murata) 26 days ago

I think != is easier to understand than ^^.

Updated by mame (Yusuke Endoh) 26 days ago

Would it be possible to have logical ^ in addition to the bitwise ^ for XOR?

I think it is possible, but we need a good reason to do so. Do you have any use case?

Updated by sawa (Tsuyoshi Sawada) 25 days ago

Unlike && and ||, which involve short-circuit evaluation, and hence are keywords rather than methods, the proposed ^^ will not involve short-circuit evaluation. Which is the intended proposal: as a keyword, or as a method?

Also available in: Atom PDF