February 12, 2007
Andrei Alexandrescu (See Website For Email) wrote:
> Bill Baxter wrote:
>> I notice the graph doesn't include complex types.
>> Is there any reason why float shouldn't be automatically converted to cfloat?
> 
> Sharp eyes :o). I was simply too lazy to include complex types. Probably real-to-complex conversion should be allowed implicitly, too, as long as the basic principle of preserving value is respected.

Implicit conversions from floats to complex types was disallowed because it caused overloading problems with math functions.

Separate functions for float and complex functions are desirable.
February 12, 2007
Walter Bright wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
>> Bill Baxter wrote:
>>> I notice the graph doesn't include complex types.
>>> Is there any reason why float shouldn't be automatically converted to cfloat?
>>
>> Sharp eyes :o). I was simply too lazy to include complex types. Probably real-to-complex conversion should be allowed implicitly, too, as long as the basic principle of preserving value is respected.
> 
> Implicit conversions from floats to complex types was disallowed because it caused overloading problems with math functions.
> 
> Separate functions for float and complex functions are desirable.

So the way things should be is: all meaning-preserving integral promotions should be kept; then, all implicit integral->floating point promotions should be severed; then, all implicit floating point->complex  should go.

Right?

Andrei
February 12, 2007
Andrei Alexandrescu (See Website For Email) wrote:
> So the way things should be is: all meaning-preserving integral promotions should be kept; then, all implicit integral->floating point promotions should be severed; then, all implicit floating point->complex  should go.
> 
> Right?

Yes. Also disallow implicit conversion of Object to void*.
February 13, 2007
Walter Bright wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
>> So the way things should be is: all meaning-preserving integral promotions should be kept; then, all implicit integral->floating point promotions should be severed; then, all implicit floating point->complex  should go.
>>
>> Right?
> 
> Yes. Also disallow implicit conversion of Object to void*.

How iz zis:

http://erdani.org/d-implicit-conversions.pdf

I put Object and void* in there for your sake :o).

Did I forget something?


Andrei
February 13, 2007
On Mon, 12 Feb 2007 16:03:14 -0800, Andrei Alexandrescu (See Website For
Email) wrote:

> 
> http://erdani.org/d-implicit-conversions.pdf

> Did I forget something?

Characters are not numbers.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Justice for David Hicks!"
13/02/2007 1:03:32 PM
February 13, 2007
Derek Parnell wrote:
> On Mon, 12 Feb 2007 16:03:14 -0800, Andrei Alexandrescu (See Website For
> Email) wrote:
> 
>> http://erdani.org/d-implicit-conversions.pdf
>  
>> Did I forget something?
> 
> Characters are not numbers. 

http://www.digitalmars.com/d/type.html specifies they are "unsigned" and also the number of bits. Their default initial value is written in hex. This made me assume that they can be treated as numbers.

Andrei
February 13, 2007
On Mon, 12 Feb 2007 18:14:50 -0800, Andrei Alexandrescu (See Website For
Email) wrote:

> Derek Parnell wrote:
>> On Mon, 12 Feb 2007 16:03:14 -0800, Andrei Alexandrescu (See Website For
>> Email) wrote:
>> 
>>> http://erdani.org/d-implicit-conversions.pdf
>> 
>>> Did I forget something?
>> 
>> Characters are not numbers.
> 
> http://www.digitalmars.com/d/type.html specifies they are "unsigned" and also the number of bits. Their default initial value is written in hex. This made me assume that they can be treated as numbers.

I was trying not to confuse implementation with theory. D implements characters using unsigned integers, but as they are not semantically numbers, it makes no sense to do many numerical operations on characters; such as adding or multiplying them. To allow them to be /implicitly/ converted to integers may lead to subtle bugs, as the compiler will miss semantically incorrect usage.

  int add(int a, int b)
  {
       return a + b;
  }

  int d = add('a', 'z');  // Should not match signature, but does.


-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Justice for David Hicks!"
13/02/2007 1:49:57 PM
February 13, 2007
Derek Parnell wrote:
> On Mon, 12 Feb 2007 16:03:14 -0800, Andrei Alexandrescu (See Website For
> Email) wrote:
> 
>> http://erdani.org/d-implicit-conversions.pdf
>  
>> Did I forget something?
> 
> Characters are not numbers. 

That's an enticing point of view, and it sounds good. But Pascal has that view, and my experience with it is it's one of the reasons Pascal sucks.

Examples:

1) converting text <=> integers
2) converting case
3) doing compression/encryption code
4) using characters as indices (isspace() for example)

Take away the implicit conversions, and such code gets littered with ugly casts.
February 13, 2007
Andrei Alexandrescu (See Website For Email) wrote:
> Walter Bright wrote:
>> Andrei Alexandrescu (See Website For Email) wrote:
>>> So the way things should be is: all meaning-preserving integral promotions should be kept; then, all implicit integral->floating point promotions should be severed; then, all implicit floating point->complex  should go.
>>>
>>> Right?
>>
>> Yes. Also disallow implicit conversion of Object to void*.
> 
> How iz zis:
> 
> http://erdani.org/d-implicit-conversions.pdf
> 
> I put Object and void* in there for your sake :o).
> 
> Did I forget something?

ubyte => char, ushort => wchar, uint => dchar.
February 13, 2007
Walter Bright wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
>> Walter Bright wrote:
>>> Andrei Alexandrescu (See Website For Email) wrote:
>>>> So the way things should be is: all meaning-preserving integral promotions should be kept; then, all implicit integral->floating point promotions should be severed; then, all implicit floating point->complex  should go.
>>>>
>>>> Right?
>>>
>>> Yes. Also disallow implicit conversion of Object to void*.
>>
>> How iz zis:
>>
>> http://erdani.org/d-implicit-conversions.pdf
>>
>> I put Object and void* in there for your sake :o).
>>
>> Did I forget something?
> 
> ubyte => char, ushort => wchar, uint => dchar.

Is that both ways??? :oO

Andrei