Jump to page: 1 2 3
Thread overview
Boolean exclusive or?
Aug 01, 2004
Ola Frid
Aug 01, 2004
Andy Friesen
Aug 01, 2004
parabolis
Aug 01, 2004
teqDruid
Aug 01, 2004
teqDruid
Aug 01, 2004
parabolis
Aug 01, 2004
teqDruid
Aug 01, 2004
parabolis
Aug 01, 2004
teqDruid
Aug 01, 2004
parabolis
Aug 01, 2004
Andy Friesen
Aug 01, 2004
Andy Friesen
Aug 01, 2004
parabolis
Aug 01, 2004
Arcane Jill
Aug 01, 2004
Lord Syl
Aug 01, 2004
Sean Kelly
Aug 01, 2004
Stephan Wienczny
Aug 01, 2004
Ola Frid
Aug 01, 2004
parabolis
Aug 01, 2004
Ola Frid
Aug 01, 2004
Arcane Jill
Aug 01, 2004
Arcane Jill
Aug 01, 2004
Ola Frid
August 01, 2004
Any chance of adding a boolean exclusive or? Like ^^?
It's a thing that too many programming languages lack, in my opinion.

/ Ola Frid
August 01, 2004
Ola Frid <olafrid atyay dtek.chalmers otday se> wrote:
> Any chance of adding a boolean exclusive or? Like ^^?
> It's a thing that too many programming languages lack, in my opinion.

Fewer than you think!

We usually call it !=

:)

 -- andy
August 01, 2004
In article <cein8f$21i8$1@digitaldaemon.com>, Ola Frid <olafrid atyay dtek.chalmers otday se> says...
>
>Any chance of adding a boolean exclusive or? Like ^^?
>It's a thing that too many programming languages lack, in my opinion.
>
>/ Ola Frid

In D, as has been much discussed in the past, a boolean value is just a int (bah!), with the type "bool" aliased to "bit".

Therefore, the operator ^ will do what you want.

# bool b = (x == y) ^ (z > 0);

Arcane Jill



August 01, 2004
In article <cej0hj$258c$1@digitaldaemon.com>, Arcane Jill says...
>
>In article <cein8f$21i8$1@digitaldaemon.com>, Ola Frid <olafrid atyay dtek.chalmers otday se> says...
>>
>>Any chance of adding a boolean exclusive or? Like ^^?
>>It's a thing that too many programming languages lack, in my opinion.
>>
>>/ Ola Frid
>
>In D, as has been much discussed in the past, a boolean value is just a int (bah!), with the type "bool" aliased to "bit".
>
>Therefore, the operator ^ will do what you want.
>
># bool b = (x == y) ^ (z > 0);
>
>Arcane Jill
>
>

Wha..what!? In D a "bit" is a "int"? But...isn't it a waste to use 32 bits when
there could be used only 8? (that is, using a (0, !0) "byte" for boolean values)


August 01, 2004
Lord Syl wrote:
> 
> Wha..what!? In D a "bit" is a "int"? But...isn't it a waste to use 32 bits when
> there could be used only 8? (that is, using a (0, !0) "byte" for boolean values)

In D, a bit is stored in one byte and arrays of bits are packed so they actually are one bit in size.


Sean
August 01, 2004
Lord Syl wrote:
> In article <cej0hj$258c$1@digitaldaemon.com>, Arcane Jill says...
> 
>>In article <cein8f$21i8$1@digitaldaemon.com>, Ola Frid <olafrid atyay
>>dtek.chalmers otday se> says...
>>
>>>Any chance of adding a boolean exclusive or? Like ^^?
>>>It's a thing that too many programming languages lack, in my opinion.
>>>
>>>/ Ola Frid
>>
>>In D, as has been much discussed in the past, a boolean value is just a int
>>(bah!), with the type "bool" aliased to "bit".
>>
>>Therefore, the operator ^ will do what you want.
>>
>># bool b = (x == y) ^ (z > 0);
>>
>>Arcane Jill
>>
>>
> 
> 
> Wha..what!? In D a "bit" is a "int"? But...isn't it a waste to use 32 bits when
> there could be used only 8? (that is, using a (0, !0) "byte" for boolean values)
> 
> 
Have you ever looked at the implementations of other languages?
On the other side. You can't easily pack some bits together. Then you would have to do some more asm operations to access it.
We live on 32bit machines today...

Stephan Wienczny
August 01, 2004
Andy Friesen wrote:

> Ola Frid <olafrid atyay dtek.chalmers otday se> wrote:
> 
>> Any chance of adding a boolean exclusive or? Like ^^?
>> It's a thing that too many programming languages lack, in my opinion.
> 
> 
> Fewer than you think!
> 
> We usually call it !=
> 
> :)
> 
>  -- andy

lol well put...
August 01, 2004
On Sun, 01 Aug 2004 07:47:23 -0700, Andy Friesen wrote:

> Ola Frid <olafrid atyay dtek.chalmers otday se> wrote:
>> Any chance of adding a boolean exclusive or? Like ^^?
>> It's a thing that too many programming languages lack, in my opinion.
> 
> Fewer than you think!
> 
> We usually call it !=
> 
> :)
> 
>   -- andy

But that only works if you're actually comparing booleans, so something like:

a.opEquals(b) != c.opEquals(d)
isn't necessarily the same as
(a.opEquals(b) == true) != (c.opEquals(d))
whereas since ^^ is a boolean comparison,
a.opEquals(b) ^^ c.opEquals(d)
should compare the same.

Yes?
August 01, 2004
On Sun, 01 Aug 2004 12:55:55 -0400, teqDruid wrote:

> On Sun, 01 Aug 2004 07:47:23 -0700, Andy Friesen wrote:
> 
>> Ola Frid <olafrid atyay dtek.chalmers otday se> wrote:
>>> Any chance of adding a boolean exclusive or? Like ^^?
>>> It's a thing that too many programming languages lack, in my opinion.
>> 
>> Fewer than you think!
>> 
>> We usually call it !=
>> 
>> :)
>> 
>>   -- andy
> 
> But that only works if you're actually comparing booleans, so something like:
> 
> a.opEquals(b) != c.opEquals(d)
> isn't necessarily the same as
> (a.opEquals(b) == true) != (c.opEquals(d))
oops! amend that to (a.opEquals(b) == true) != (c.opEquals(d) == true)

> whereas since ^^ is a boolean comparison,
> a.opEquals(b) ^^ c.opEquals(d)
> should compare the same.
> 
> Yes?

August 01, 2004
teqDruid wrote:

> On Sun, 01 Aug 2004 07:47:23 -0700, Andy Friesen wrote:
> 
> 
>>Ola Frid <olafrid atyay dtek.chalmers otday se> wrote:
>>
>>>Any chance of adding a boolean exclusive or? Like ^^?
>>>It's a thing that too many programming languages lack, in my opinion.
>>
>>Fewer than you think!
>>
>>We usually call it !=
>>
>>:)
>>
>>  -- andy
> 
> 
> But that only works if you're actually comparing booleans, so something
> like:
> 
> a.opEquals(b) != c.opEquals(d)
> isn't necessarily the same as
> (a.opEquals(b) == true) != (c.opEquals(d) == true) // <- amended
> whereas since ^^ is a boolean comparison,
> a.opEquals(b) ^^ c.opEquals(d)
> should compare the same.
> 

Only if you create a class and overload the opEquals operator and return a byte/ubyte/int/uint/long/ulong instead of type bit.
Of course you can also overload the opEquals with return type Object...

Sadlly the compiler does not seem to be consistent about not being able to convert an int to a bit.

« First   ‹ Prev
1 2 3