Thread overview | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 01, 2004 Boolean exclusive or? | ||||
---|---|---|---|---|
| ||||
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 Re: Boolean exclusive or? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ola Frid | 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 Re: Boolean exclusive or? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ola Frid | 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 Re: Boolean exclusive or? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Arcane Jill | 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 Re: Boolean exclusive or? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lord Syl | 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 Re: Boolean exclusive or? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lord Syl | 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 Re: Boolean exclusive or? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | 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 Re: Boolean exclusive or? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | 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 Re: Boolean exclusive or? | ||||
---|---|---|---|---|
| ||||
Posted in reply to teqDruid | 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 Re: Boolean exclusive or? | ||||
---|---|---|---|---|
| ||||
Posted in reply to teqDruid | 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.
|
Copyright © 1999-2021 by the D Language Foundation