You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Matt Benson <gu...@gmail.com> on 2011/07/17 02:59:35 UTC

xor condition

Currently each nested condition is xor'd against the cumulative result, thus:

xor(true, false) == true
xor(true, false, true) == false
xor(true, false, true, false) == false

Is this correct?  It would seem that semantically an xor over multiple
nested conditions should mean that exactly one value should evaluate
true in order for the xor operation to yield truth.

Matt

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: xor condition

Posted by Matt Benson <gu...@gmail.com>.
On Wed, Jul 20, 2011 at 5:44 AM, Jesse Glick <je...@oracle.com> wrote:
> On 07/16/2011 08:59 PM, Matt Benson wrote:
>>
>> xor(true, false) == true
>> xor(true, false, true) == false
>> xor(true, false, true, false) == false
>>
>> Is this correct?
>
> Follows the usual semantics; cf.:
> http://en.wikipedia.org/wiki/Exclusive_or#Associativity_and_commutativity
>
>> It would seem that semantically an xor over multiple
>> nested conditions should mean that exactly one value should evaluate
>> true in order for the xor operation to yield truth.
>
> Which is in fact the case in the examples you mentioned, but probably you
> are thinking of
>
> xor(true, true, true) == true
>
> which is consistent with the algebraic definition, and the behavior of
> Java's ^ operator for that matter. If you wanted a condition with the
> semantics you describe, it should be named something else.
>

Thanks, Jesse--I think you cleared it up in my head:

and(x, y, z) => x & y & z
or(x, y, z) => x | y | z
xor(x, y, z) => x ^ y ^ z

Thanks!

Matt

>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: xor condition

Posted by Jesse Glick <je...@oracle.com>.
On 07/16/2011 08:59 PM, Matt Benson wrote:
> xor(true, false) == true
> xor(true, false, true) == false
> xor(true, false, true, false) == false
>
> Is this correct?

Follows the usual semantics; cf.: http://en.wikipedia.org/wiki/Exclusive_or#Associativity_and_commutativity

> It would seem that semantically an xor over multiple
> nested conditions should mean that exactly one value should evaluate
> true in order for the xor operation to yield truth.

Which is in fact the case in the examples you mentioned, but probably you are thinking of

xor(true, true, true) == true

which is consistent with the algebraic definition, and the behavior of Java's ^ operator for that matter. If you wanted a condition with the semantics you describe, it 
should be named something else.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: xor condition

Posted by Stefan Bodewig <bo...@apache.org>.
On 2011-07-17, Matt Benson wrote:

>> ,----
>> | It only evaluates to true if an odd number of nested conditions are true.
>> `----

> So is this an accepted "kind of xor"?

Accepted by the original author (Steve IIRC), silently accepted by all
reviewers back then and in a way accepted as "that's what it does" by
Ant's users, I guess 8-)

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: xor condition

Posted by Matt Benson <gu...@gmail.com>.
On Sat, Jul 16, 2011 at 10:21 PM, Stefan Bodewig <bo...@apache.org> wrote:
> On 2011-07-17, Matt Benson wrote:
>
>> Currently each nested condition is xor'd against the cumulative result, thus:
>
>> xor(true, false) == true
>> xor(true, false, true) == false
>> xor(true, false, true, false) == false
>
>> Is this correct?  It would seem that semantically an xor over multiple
>> nested conditions should mean that exactly one value should evaluate
>> true in order for the xor operation to yield truth.
>
> While my gut feeling agrees with what you describe the documentation of
> the xor description actually says
>
> ,----
> | It only evaluates to true if an odd number of nested conditions are true.
> `----
>

So is this an accepted "kind of xor"?

> If you need the "other kind of xor" then a new container would be
> required.  "exactlyOneOf" or something similar?

I don't need it, personally, yet.  Was working in Commons Lang,
noticed the discrepancy between oacl.BooleanUtils.xor() and Ant's xor
condition, and wanted to follow up.

br,
Matt

>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: xor condition

Posted by Stefan Bodewig <bo...@apache.org>.
On 2011-07-17, Matt Benson wrote:

> Currently each nested condition is xor'd against the cumulative result, thus:

> xor(true, false) == true
> xor(true, false, true) == false
> xor(true, false, true, false) == false

> Is this correct?  It would seem that semantically an xor over multiple
> nested conditions should mean that exactly one value should evaluate
> true in order for the xor operation to yield truth.

While my gut feeling agrees with what you describe the documentation of
the xor description actually says

,----
| It only evaluates to true if an odd number of nested conditions are true.
`----

If you need the "other kind of xor" then a new container would be
required.  "exactlyOneOf" or something similar?

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org