Why Ruby doesn't have some xor operator?

P

Pavel Smerk

Hello,

#{subj} --- not only (False|True|Nil)Class#^, but some general one, like
the and and or are. May be also ^^ with higher precedence.

P.
 
R

Robert Klemme

Hello,

#{subj} --- not only (False|True|Nil)Class#^, but some general one, like
the and and or are. May be also ^^ with higher precedence.

What semantic do you expect that operator to have? If you want it for
boolean XOR you can do

Fixnum still works
=> 3

Kind regards

robert
 
D

Daniel Martin

Pavel Smerk said:
Hello,

#{subj} --- not only (False|True|Nil)Class#^, but some general one,
like the and and or are. May be also ^^ with higher precedence.

I'll note that I find the "and" and "or" operators primarily useful
for the fact that they short-circuit (that is, the right hand side
doesn't get evaluated unless it needs to be) and because they always
return one of their arguments.

Note that neither of those properties can hold with an xor operator.
You obviously can't short-circuit, and secondly what do you return
when both arguments are true? nil or false?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top