September 07, 2021

On Tuesday, 7 September 2021 at 01:34:01 UTC, Basile B. wrote:

>

On Wednesday, 1 September 2021 at 04:40:37 UTC, Виталий Фадеев wrote:

>

I want say "Thank you!" to all who works under D.

I see the result of your work, even if it is small, even the size of a byte.
I use D and see your gift.
I like. :)

while this code looks natural and obvious, although pointless

module m;

struct S { int i; }

S _s;

S s (){return _s;}

void main()
{
    s().i = 42;
}

the reality is that i can only be accessed through a pointer to a S (you want a deref of the address plus a offset).but s returns a S by value... so a temporary is created.

All the time we write code that compiles but this code just compiles because the front end will help us, in this case, by turning s() into a lvalue.

so we can indeed say thanks. what you think just works actually requires some unexpected rewrites, like all the time.

Don't you think it would be better to raise a warning though instead of silently fixing it?

It would help people understand the differences between structs and classes better, and when they will be using them in a much more complex set of circumstances where the compiler won't be able to detect what they're doing, they'll use them the right way.

This seems like setting them up for frustration in the future, since one can definitely run into a case where struct will purely be treated as a value type and then the user will feel that the behaviour is inconsistent with what they've experienced.

This reminds me of single length string literals being treated as a character.

void main(){
     char[5] a = "y";//shouldn't compile, but it does
     char[5] b = 'y';
     writeln(a);
     writeln(b);
}


Output:
y
yyyyy

Was it a good thing that the compiler rewrote the string into a char in this case? Wouldn't it be better if an error/warning was provided instead?

September 07, 2021

On Tuesday, 7 September 2021 at 05:01:30 UTC, Tejas wrote:

>

This reminds me of single length string literals being treated as a character.

void main(){
     char[5] a = "y";//shouldn't compile, but it does
     char[5] b = 'y';
     writeln(a);
     writeln(b);
}


Output:
y
yyyyy

Was it a good thing that the compiler rewrote the string into a char in this case? Wouldn't it be better if an error/warning was provided instead?

This example works with a initialized to "yy" as well, or "yyxx". The chars not provided are initialized to 0 (rather than 255 if the variable weren't initialized at all). This seems like a nice way to reuse a large fixed buffer that initially has small relevant content, like char[255] line = "hello";

It doesn't initialize the entire array to 'y', so it's not treating "y" as the same as 'y'.

September 07, 2021

On Tuesday, 7 September 2021 at 05:09:39 UTC, jfondren wrote:

>

On Tuesday, 7 September 2021 at 05:01:30 UTC, Tejas wrote:

>

This reminds me of single length string literals being treated as a character.

void main(){
     char[5] a = "y";//shouldn't compile, but it does
     char[5] b = 'y';
     writeln(a);
     writeln(b);
}


Output:
y
yyyyy

Was it a good thing that the compiler rewrote the string into a char in this case? Wouldn't it be better if an error/warning was provided instead?

This example works with a initialized to "yy" as well, or "yyxx". The chars not provided are initialized to 0 (rather than 255 if the variable weren't initialized at all). This seems like a nice way to reuse a large fixed buffer that initially has small relevant content, like char[255] line = "hello";

It doesn't initialize the entire array to 'y', so it's not treating "y" as the same as 'y'.

Oh... that looks more convenient than

char[10] a;
a[0..5] = 'y';

Can't even initialize a with index 0 at point of declaration unless size of definition is same as size of array, basically making

char[10] a = [0:'y',1:'y',2:'y',3:'y',4:'y'];

impossible.

Agh, maybe that thing needs to exist after all

September 07, 2021

On Tuesday, 7 September 2021 at 05:09:39 UTC, jfondren wrote:

>

On Tuesday, 7 September 2021 at 05:01:30 UTC, Tejas wrote:

>

This reminds me of single length string literals being treated as a character.

void main(){
     char[5] a = "y";//shouldn't compile, but it does
     char[5] b = 'y';
     writeln(a);
     writeln(b);
}


Output:
y
yyyyy

Was it a good thing that the compiler rewrote the string into a char in this case? Wouldn't it be better if an error/warning was provided instead?

This example works with a initialized to "yy" as well, or "yyxx". The chars not provided are initialized to 0 (rather than 255 if the variable weren't initialized at all). This seems like a nice way to reuse a large fixed buffer that initially has small relevant content, like char[255] line = "hello";

It doesn't initialize the entire array to 'y', so it's not treating "y" as the same as 'y'.

Seems strange to only permit this with a string literal though.

unittest {
    char[3] a;
    char[2] b = '!';

    // this is OK
    a = "!!";
    assert(a == [33, 33, 0]);

    // Error: mismatched array lengths, 3 and 2
    assert(!__traits(compiles, a = ['!', '!']));
    assert(!__traits(compiles, { a[] = b[]; }));
}
September 07, 2021

On Tuesday, 7 September 2021 at 05:01:30 UTC, Tejas wrote:

>

This reminds me of single length string literals being treated as a character.

void main(){
     char[5] a = "y";//shouldn't compile, but it does
     char[5] b = 'y';
     writeln(a);
     writeln(b);
}


Output:
y
yyyyy

Was it a good thing that the compiler rewrote the string into a char in this case? Wouldn't it be better if an error/warning was provided instead?

What you think is happening is not actually what's happening.

It's not turning the string into a char. It's actually copying the contents of the string (char array) into the char array.

It's evident by:

char[5] c = "hello";

c will be "hello"

And in the case of ex.

char[5] c = "hello world!";

You actually get a runtime error but arguably it should be a compile-time error since the size of c and the size of the string is available at compile-time.

I would agree with that it shouldn't be allowed at all however, but unfortunately this is allowed because string is really an alias for an array and not a type in itself.

September 07, 2021

On Tuesday, 7 September 2021 at 06:12:38 UTC, bauss wrote:

>

On Tuesday, 7 September 2021 at 05:01:30 UTC, Tejas wrote:

>

This reminds me of single length string literals being treated as a character.

void main(){
     char[5] a = "y";//shouldn't compile, but it does
     char[5] b = 'y';
     writeln(a);
     writeln(b);
}


Output:
y
yyyyy

Was it a good thing that the compiler rewrote the string into a char in this case? Wouldn't it be better if an error/warning was provided instead?

What you think is happening is not actually what's happening.

It's not turning the string into a char. It's actually copying the contents of the string (char array) into the char array.

It's evident by:

char[5] c = "hello";

c will be "hello"

And in the case of ex.

char[5] c = "hello world!";

You actually get a runtime error but arguably it should be a compile-time error since the size of c and the size of the string is available at compile-time.

I would agree with that it shouldn't be allowed at all however, but unfortunately this is allowed because string is really an alias for an array and not a type in itself.

Nope, there is definitely some special-casing going on here.

The following doesn't work:

import std.stdio;

void main(){
    immutable (char)[] s = "hello";
    char[5] a = s;
    writeln(a);
    immutable (int)[] i = [10];
    writeln(i);
    int[] I = i;
}

Turn I into a static array, and you get runtime error for some strange reason.

This is an inconsistency.

But considering the use case presented by @jfondren, I'm not sure whether we should remove it for consistency's sake

September 07, 2021
06.09.2021 16:11, Alexandru Ermicioi пишет:
> On Monday, 6 September 2021 at 08:15:02 UTC, drug wrote:
>>
>> Unfortunately I agree to you. When I started using D this forum was the brilliant place where many smart guys shared different information and I learnt many useful things here. But currently it is quiet and boring place because (I guess) the community lost many its core contributors and continue to do it. No offense intended.
> 
> Or it could be the case that you already know most of discussed stuff, and it is not as brilliant as it was when discovered for first time :).
> 

I hope so :)

September 07, 2021

On Tuesday, 7 September 2021 at 05:01:30 UTC, Tejas wrote:

>

On Tuesday, 7 September 2021 at 01:34:01 UTC, Basile B. wrote:

>

On Wednesday, 1 September 2021 at 04:40:37 UTC, Виталий Фадеев wrote:

>

I want say "Thank you!" to all who works under D.

I see the result of your work, even if it is small, even the size of a byte.
I use D and see your gift.
I like. :)

while this code looks natural and obvious, although pointless

module m;

struct S { int i; }

S _s;

S s (){return _s;}

void main()
{
    s().i = 42;
}

the reality is that i can only be accessed through a pointer to a S (you want a deref of the address plus a offset).but s returns a S by value... so a temporary is created.

All the time we write code that compiles but this code just compiles because the front end will help us, in this case, by turning s() into a lvalue.

so we can indeed say thanks. what you think just works actually requires some unexpected rewrites, like all the time.

Don't you think it would be better to raise a warning though instead of silently fixing it?

no. as compiler experiment people can add a flag to generated temproaries and then printf on a visitor for VarExp and then will probabably be surprised by the amount of message printf'd like 2567 times

"look boy am saving expressivity for ya here"

>

It would help people understand the differences between [...]

September 07, 2021

On Tuesday, 7 September 2021 at 06:45:02 UTC, Tejas wrote:

>

On Tuesday, 7 September 2021 at 06:12:38 UTC, bauss wrote:

>

On Tuesday, 7 September 2021 at 05:01:30 UTC, Tejas wrote:

>

This reminds me of single length string literals being treated as a character.

void main(){
     char[5] a = "y";//shouldn't compile, but it does
     char[5] b = 'y';
     writeln(a);
     writeln(b);
}


Output:
y
yyyyy

Was it a good thing that the compiler rewrote the string into a char in this case? Wouldn't it be better if an error/warning was provided instead?

What you think is happening is not actually what's happening.

It's not turning the string into a char. It's actually copying the contents of the string (char array) into the char array.

It's evident by:

char[5] c = "hello";

c will be "hello"

And in the case of ex.

char[5] c = "hello world!";

You actually get a runtime error but arguably it should be a compile-time error since the size of c and the size of the string is available at compile-time.

I would agree with that it shouldn't be allowed at all however, but unfortunately this is allowed because string is really an alias for an array and not a type in itself.

Nope, there is definitely some special-casing going on here.

The following doesn't work:

import std.stdio;

void main(){
    immutable (char)[] s = "hello";
    char[5] a = s;
    writeln(a);
    immutable (int)[] i = [10];
    writeln(i);
    int[] I = i;
}

Turn I into a static array, and you get runtime error for some strange reason.

This is an inconsistency.

But considering the use case presented by @jfondren, I'm not sure whether we should remove it for consistency's sake

Yeah, what I was saying is that there's some funky thing going on but that it wasn't turning the string into a char but rather somehow attempting to copy the string into the char array.

September 07, 2021
On Tuesday, 7 September 2021 at 07:34:40 UTC, drug wrote:
>> Or it could be the case that you already know most of discussed stuff, and it is not as brilliant as it was when discovered for first time :).
>> 
>
> I hope so :)

Perhaps read some of the old rants then: https://dlang-group.iteye.com/group/topic/20404
A lot of theses issues were solved, and not thanks to the rant.

The old forums were good but also a festering ground for all kinds of flamewars.