5 days ago
On Saturday, 1 May 2021 at 19:49:51 UTC, russhy wrote:
> On Saturday, 1 May 2021 at 12:22:50 UTC, evilrat wrote:
>> On Saturday, 1 May 2021 at 11:50:27 UTC, Adam D. Ruppe wrote:
>>>[...]
>>
>> Is there one in Phobos? Anyway this works, but maybe it can be made more type safe with constraints or just with improved symtax.
>>
>> ```d
>> // compiles with -vgc and -betterC (weird, also without import stdc.core.stdio)
>> import std.range : ElementType;
>>
>> template staticArray(alias T)
>> {
>> 	enum ElementType!(typeof(T))[T.length] staticArray = T;
>> }
>>
>> extern(C) void main()
>> {
>> 	import core.stdc.stdio;
>> 	auto arr = staticArray!([1,2,3]);
>> 	pragma(msg, typeof(arr)); // int[3]
>> 	foreach(i; arr)
>> 		printf("%d\n", i);
>> }
>> ```
>
>
> don't you realize something is weird?
>
> someone is asking to be able to do auto a = [1, 2, 3]
>
> and you propose a template?
>
> this is asking people to look for alternative language
>
> auto a = new[1,2,3]  <== this should be allocated array
> auto a = [1,2,3] <== this should be static array
>
> let's fix that, shall we? instead of telling people to bloat their files with templates

Is there any way to enable this in the language?

```d
auto a = [1,2,3] + [4,5,6]; //[5,7,9]
```

I want to allow the operation.

If I made a dmd fork, could I change this behavior "easily" or would it require a blood sacrifice
5 days ago

On Sunday, 2 May 2021 at 05:57:02 UTC, evilrat wrote:

>

On Saturday, 1 May 2021 at 19:49:51 UTC, russhy wrote:

>

On Saturday, 1 May 2021 at 12:22:50 UTC, evilrat wrote:

>

On Saturday, 1 May 2021 at 11:50:27 UTC, Adam D. Ruppe wrote:

>

or you can use the library .staticArray thing to expressly indicate your intention on the original foo

foo([1,2,3].staticArray);

Is there one in Phobos? Anyway this works, but maybe it can be made more type safe with constraints or just with improved symtax.

// compiles with -vgc and -betterC (weird, also without import stdc.core.stdio)
import std.range : ElementType;

template staticArray(alias T)
{
	enum ElementType!(typeof(T))[T.length] staticArray = T;
}

extern(C) void main()
{
	import core.stdc.stdio;
	auto arr = staticArray!([1,2,3]);
	pragma(msg, typeof(arr)); // int[3]
	foreach(i; arr)
		printf("%d\n", i);
}

don't you realize something is weird?

someone is asking to be able to do auto a = [1, 2, 3]

and you propose a template?

this is asking people to look for alternative language

auto a = new[1,2,3] <== this should be allocated array
auto a = [1,2,3] <== this should be static array

let's fix that, shall we? instead of telling people to bloat their files with templates

You see only what you wanted to see.

Let me clarify something.
That code proves that unlike it was stated "array type information is gone" it actually isn't, which this code proves.
It provides workaround just is case.
I'm not forcing anyone to use it, and there is simpler solution (still a template one) in phobos.
And finally, I haven't said anything like "D DONT NEED THIS, STFU AND USE HACKS".

But after recent discussion you seem to trigger just by seeing my posts. No thanks I don't need any stalkers following me around.

i'm not stalking you, i don't even read the user name when i reply to messages, i focus on their content

today is you, yesterday it was another person, tomorow will probably be another person, that's the way it is, i find things that annoys me, i reply

nobody else seems to be "triggered" by the need of such "workaround", i decided it would be me

4 days ago

On Saturday, 1 May 2021 at 19:49:51 UTC, russhy wrote:

>

On Saturday, 1 May 2021 at 12:22:50 UTC, evilrat wrote:

>

On Saturday, 1 May 2021 at 11:50:27 UTC, Adam D. Ruppe wrote:

>

or you can use the library .staticArray thing to expressly indicate your intention on the original foo

foo([1,2,3].staticArray);

Is there one in Phobos? Anyway this works, but maybe it can be made more type safe with constraints or just with improved symtax.

// compiles with -vgc and -betterC (weird, also without import stdc.core.stdio)
import std.range : ElementType;

template staticArray(alias T)
{
	enum ElementType!(typeof(T))[T.length] staticArray = T;
}

extern(C) void main()
{
	import core.stdc.stdio;
	auto arr = staticArray!([1,2,3]);
	pragma(msg, typeof(arr)); // int[3]
	foreach(i; arr)
		printf("%d\n", i);
}

don't you realize something is weird?

someone is asking to be able to do auto a = [1, 2, 3]

and you propose a template?

this is asking people to look for alternative language

auto a = new[1,2,3]  <== this should be allocated array
auto a = [1,2,3] <== this should be static array

let's fix that, shall we? instead of telling people to bloat their files with templates

I agree that the non-obvious allocation is kind of a problem and new [ 1, 2, 3 ] would be more explicit, but where I see the actual issue isn't where you think it is. In @nogc code, the compiler tells you that an allocation takes place and you look for solutions to avoid it (there are multiple approaches, but no general one).

4 days ago

On Sunday, 2 May 2021 at 08:05:49 UTC, Imperatorn wrote:

>

Is there any way to enable this in the language?

auto a = [1,2,3] + [4,5,6]; //[5,7,9]

I want to allow the operation.

If I made a dmd fork, could I change this behavior "easily" or would it require a blood sacrifice

You could enable this easily using a wrapping struct template. Have a look at this: https://run.dlang.io/is/6CNgpy

In short, the solution is very elegant, very general, and only requires you to make two keystrokes .v before the operation. Alternatively, you can use v(1, 2, 3) instead of a slice literal.

3 days ago

On Sunday, 2 May 2021 at 08:07:58 UTC, Imperatorn wrote:

>

On Saturday, 1 May 2021 at 19:49:51 UTC, russhy wrote:

>

On Saturday, 1 May 2021 at 12:22:50 UTC, evilrat wrote:

>

On Saturday, 1 May 2021 at 11:50:27 UTC, Adam D. Ruppe wrote:

>

[...]

Is there one in Phobos? Anyway this works, but maybe it can be made more type safe with constraints or just with improved symtax.

// compiles with -vgc and -betterC (weird, also without import stdc.core.stdio)
import std.range : ElementType;

template staticArray(alias T)
{
	enum ElementType!(typeof(T))[T.length] staticArray = T;
}

extern(C) void main()
{
	import core.stdc.stdio;
	auto arr = staticArray!([1,2,3]);
	pragma(msg, typeof(arr)); // int[3]
	foreach(i; arr)
		printf("%d\n", i);
}

don't you realize something is weird?

someone is asking to be able to do auto a = [1, 2, 3]

and you propose a template?

this is asking people to look for alternative language

auto a = new[1,2,3] <== this should be allocated array
auto a = [1,2,3] <== this should be static array

let's fix that, shall we? instead of telling people to bloat their files with templates

Is there any way to enable this in the language?

auto a = [1,2,3] + [4,5,6]; //[5,7,9]

I want to allow the operation.

If I made a dmd fork, could I change this behavior "easily" or would it require a blood sacrifice

I think there was once a PR that made this nice and easy:

https://github.com/dlang/dmd/pull/3615

auto a[$] = [1,2,3];

I was disappointed it never got accepted but I am sure there were good reasons. At the time I think it was "this should be a library solution" and that was probably where staticArray came from

3 days ago

On Tuesday, 4 May 2021 at 01:59:48 UTC, norm wrote:

>
auto a[$] = [1,2,3];

gah! too much C not enough D lately; auto[$] a = [1,2,3];

3 days ago

On Tuesday, 4 May 2021 at 00:34:49 UTC, Q. Schroll wrote:

>

On Sunday, 2 May 2021 at 08:05:49 UTC, Imperatorn wrote:

>

Is there any way to enable this in the language?

auto a = [1,2,3] + [4,5,6]; //[5,7,9]

I want to allow the operation.

If I made a dmd fork, could I change this behavior "easily" or would it require a blood sacrifice

You could enable this easily using a wrapping struct template. Have a look at this: https://run.dlang.io/is/6CNgpy

In short, the solution is very elegant, very general, and only requires you to make two keystrokes .v before the operation. Alternatively, you can use v(1, 2, 3) instead of a slice literal.

Interesting! Even more cool if not the .v was required tho 😁

3 days ago

On Tuesday, 4 May 2021 at 01:59:48 UTC, norm wrote:

>

https://github.com/dlang/dmd/pull/3615

auto a[$] = [1,2,3];

I was disappointed it never got accepted but I am sure there were good reasons. At the time I think it was "this should be a library solution" and that was probably where staticArray came from

Oh that is pretty disappointing...

I actually intuitively tried to do this while I was learning D. So IMO it fits the language perfectly.

It looks like it wasn't merged because Andrei and Walter thought it complicates the language needlessly (https://github.com/dlang/dmd/pull/3615#issuecomment-72397283).

There's still this DIP: https://github.com/dlang/DIPs/blob/master/DIPs/DIP1039.md & https://forum.dlang.org/thread/ucqyqkvaznbxkasvdjpx@forum.dlang.org?page=3.

3 days ago

On Tuesday, 4 May 2021 at 10:09:59 UTC, Blatnik wrote:

>

There's still this DIP: https://github.com/dlang/DIPs/blob/master/DIPs/DIP1039.md & https://forum.dlang.org/thread/ucqyqkvaznbxkasvdjpx@forum.dlang.org?page=3.

The DIP author asked me to put this on hold until he can complete an implementation. His schedule prohibits that happening for a while yet. My current expectation is that we'll be ready to move forward with it by September.

3 days ago

On Tuesday, 4 May 2021 at 10:09:59 UTC, Blatnik wrote:

>

On Tuesday, 4 May 2021 at 01:59:48 UTC, norm wrote:

>

[...]

Oh that is pretty disappointing...

I actually intuitively tried to do this while I was learning D. So IMO it fits the language perfectly.

It looks like it wasn't merged because Andrei and Walter thought it complicates the language needlessly (https://github.com/dlang/dmd/pull/3615#issuecomment-72397283).

There's still this DIP: https://github.com/dlang/DIPs/blob/master/DIPs/DIP1039.md & https://forum.dlang.org/thread/ucqyqkvaznbxkasvdjpx@forum.dlang.org?page=3.

Would be nice if that DIP got some love. But, that would still not enable stuff like

auto a = [1,2,3] + [3,2,1]; //[4,4,4]

right?

1 2 3 4 5