go ahead... be a heretic PerlMonks

Re^5: Burned by precedence rules (== true)

by ikegami (Pope)
 on Dec 30, 2008 at 20:09 UTC ( #733338=note: print w/ replies, xml ) Need Help??

in reply to Re^4: Burned by precedence rules (== true)
in thread Burned by precedence rules

There's a logical operator for that: xor

```if ( !\$x == !\$y) ) # bool(\$x) == bool(\$y)
if ( !\$x != !\$y  ) # bool(\$x) != bool(\$y)
can be written as
```if ( !(\$x xor \$y) ) # bool(\$x) == bool(\$y)
if (   \$x xor \$y  ) # bool(\$x) != bool(\$y)

Unforunately, both sets have readability issues.

Comment on Re^5: Burned by precedence rules (== true)
Replies are listed 'Best First'.
Re^6: Burned by precedence rules (== true)
by TimToady (Parson) on Dec 30, 2008 at 20:49 UTC
In Perl 6 we can use positive boolean context, which helps readability a little:
```if ?\$x == ?\$y {...}
if ?\$x != ?\$y {...}
We can use junctions, which again helps the different case more than the same case:
```if not \$x ^ \$y {...}
if \$x ^ \$y {...}
or if you prefer:
```if !one(\$x,\$y) {...}
if one(\$x,\$y) {...}
That's probably enough ways to do it...

Nah. Clearly this demonstrates the utility of a few "Boolean comparison" operators:

```    if \$isFree ?= \$isEasy
if \$isOne !?= \$isOther

or  die "Inconsistent state";

system \$verifyUser
or   die "You are not just either a User or an Admin";

;)

- tye

Well, we can't use eqv because we already use that for something else, but we do have a Boolean not-equal already:
```    \$x ?^ \$y
What we don't have is a Boolean equal. I thought about adding:
```    \$x ?= \$y
but people would probably think that means:
```    \$x = \$x ? \$y;
which is nonsense, but they'd still think it. :-)

Anyway, the utility is not worth the extra complexity, in my opinion. Comparing two Booleans for equivalence is an odd enough thing to do that I don't mind if it looks a little odd.

Re^6: Burned by precedence rules (== true)
by demerphq (Chancellor) on Dec 31, 2008 at 00:01 UTC

Ah yes, scalar xor, i always forget about it. Personally the !\$x == !\$y makes more sense to me than !(\$x xor \$y). But whatever.

---
\$world=~s/war/peace/g

Create A New User
Node Status?
node history
Node Type: note [id://733338]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (11)
As of 2015-11-30 11:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?