Re: static array with inferred size

2017-09-22 Thread Jonathan M Davis via Digitalmars-d
On Friday, September 22, 2017 08:19:32 Steven Schveighoffer via Digitalmars- d wrote: > On 9/22/17 3:55 AM, Dominikus Dittes Scherkl wrote: > > On Thursday, 21 September 2017 at 13:58:14 UTC, Timon Gehr wrote: > >> On 21.09.2017 12:33, Per Nordlöw wrote: > >>> On Wednesday, 20 September 2017 at

Re: static array with inferred size

2017-09-22 Thread Steven Schveighoffer via Digitalmars-d
On 9/22/17 3:55 AM, Dominikus Dittes Scherkl wrote: On Thursday, 21 September 2017 at 13:58:14 UTC, Timon Gehr wrote: On 21.09.2017 12:33, Per Nordlöw wrote: On Wednesday, 20 September 2017 at 18:41:51 UTC, Timon Gehr wrote: Can that be done without breakages? -- Andrei No. Are thinking

Re: static array with inferred size

2017-09-22 Thread Dominikus Dittes Scherkl via Digitalmars-d
On Thursday, 21 September 2017 at 13:58:14 UTC, Timon Gehr wrote: On 21.09.2017 12:33, Per Nordlöw wrote: On Wednesday, 20 September 2017 at 18:41:51 UTC, Timon Gehr wrote: Can that be done without breakages? -- Andrei No. Are thinking about     typeof([1,2]) changing from     int[]

Re: static array with inferred size

2017-09-21 Thread jmh530 via Digitalmars-d
On Wednesday, 20 September 2017 at 16:34:36 UTC, Andrei Alexandrescu wrote: On 09/20/2017 08:36 AM, jmh530 wrote: On Wednesday, 20 September 2017 at 12:10:47 UTC, Andrei Alexandrescu wrote: How would this be useful? -- Andrei Really just an additional convenience, instead of writing

Re: static array with inferred size

2017-09-21 Thread Timon Gehr via Digitalmars-d
On 21.09.2017 12:33, Per Nordlöw wrote: On Wednesday, 20 September 2017 at 18:41:51 UTC, Timon Gehr wrote: Can that be done without breakages? -- Andrei No. Are thinking about     typeof([1,2]) changing from     int[] to     int[2] ? Yes, and everything that entails, for example:

Re: static array with inferred size

2017-09-21 Thread Steven Schveighoffer via Digitalmars-d
On 9/20/17 1:33 PM, ag0aep6g wrote: On 09/20/2017 06:55 PM, Steven Schveighoffer wrote: On 9/20/17 11:48 AM, Dgame wrote: [...] Unqual!T[n] s(T, size_t n)(T[n] arr) {  return arr; } auto a = "hallo".s; writeln(typeof(a).stringof); // char[5] [...] Still it can't handle the

Re: static array with inferred size

2017-09-21 Thread Per Nordlöw via Digitalmars-d
On Wednesday, 20 September 2017 at 18:41:51 UTC, Timon Gehr wrote: Can that be done without breakages? -- Andrei No. Are thinking about typeof([1,2]) changing from int[] to int[2] ?

Re: static array with inferred size

2017-09-20 Thread Timon Gehr via Digitalmars-d
On 20.09.2017 18:34, Andrei Alexandrescu wrote: I do strongly disagree with this approach, rather we should type array literals as static arrays by default and rely on implicit conversion to slices. Can that be done without breakages? -- Andrei No.

Re: static array with inferred size

2017-09-20 Thread ag0aep6g via Digitalmars-d
On 09/20/2017 06:55 PM, Steven Schveighoffer wrote: On 9/20/17 11:48 AM, Dgame wrote: [...] Unqual!T[n] s(T, size_t n)(T[n] arr) {  return arr; } auto a = "hallo".s; writeln(typeof(a).stringof); // char[5] [...] Still it can't handle the case of: ubyte[3] x = [1, 2, 3];

Re: static array with inferred size

2017-09-20 Thread Steven Schveighoffer via Digitalmars-d
On 9/20/17 11:48 AM, Dgame wrote: Works: char[5] b = "hallo".s; Sure, but completely misses the point! Otherwise you could simply use Unqual: Unqual!T[n] s(T, size_t n)(T[n] arr) { return arr; } auto a = "hallo".s; writeln(typeof(a).stringof); // char[5] This

Re: static array with inferred size

2017-09-20 Thread Andrei Alexandrescu via Digitalmars-d
On 09/20/2017 08:36 AM, jmh530 wrote: On Wednesday, 20 September 2017 at 12:10:47 UTC, Andrei Alexandrescu wrote: How would this be useful? -- Andrei Really just an additional convenience, instead of writing slice[0..$, 0..$, 0..$, i], you would write slice[.., .., .., i]. The result

Re: static array with inferred size

2017-09-20 Thread Andrei Alexandrescu via Digitalmars-d
On 09/20/2017 08:41 AM, Stefan Koch wrote: On Wednesday, 20 September 2017 at 12:08:45 UTC, Andrei Alexandrescu wrote: On 09/20/2017 07:49 AM, Jonathan M Davis wrote: On Wednesday, September 20, 2017 10:59:56 Per Nordlöw via Digitalmars-d wrote: On Wednesday, 20 September 2017 at 09:13:52

Re: static array with inferred size

2017-09-20 Thread Dgame via Digitalmars-d
On Wednesday, 20 September 2017 at 14:15:30 UTC, Steven Schveighoffer wrote: On 9/20/17 3:12 AM, Dgame wrote: http://p0nce.github.io/d-idioms/#@nogc-Array-Literals:-Breaking-the-Limits This is plain stack corruption, you should fix that. The s template seems useful, but still I can't get

Re: static array with inferred size

2017-09-20 Thread Steven Schveighoffer via Digitalmars-d
On 9/20/17 3:12 AM, Dgame wrote: http://p0nce.github.io/d-idioms/#@nogc-Array-Literals:-Breaking-the-Limits This is plain stack corruption, you should fix that. The s template seems useful, but still I can't get my use case to work with it: T[n] s(T, size_t n)(auto ref T[n] array) pure

Re: static array with inferred size

2017-09-20 Thread Steven Schveighoffer via Digitalmars-d
On 9/20/17 1:36 AM, Andrei Alexandrescu wrote: On 9/19/17 8:47 PM, Steven Schveighoffer wrote: This needs to happen. e.g.: char[$] arr = "hello"; // syntax up for debate, but I like this. I can't think of a correct way to do this that doesn't heap-allocate and is DRY. D is so powerful,

Re: static array with inferred size

2017-09-20 Thread Jonathan M Davis via Digitalmars-d
On Wednesday, September 20, 2017 12:59:02 Meta via Digitalmars-d wrote: > On Wednesday, 20 September 2017 at 12:41:57 UTC, Stefan Koch > > wrote: > > On Wednesday, 20 September 2017 at 12:08:45 UTC, Andrei > > > > Alexandrescu wrote: > >> On 09/20/2017 07:49 AM, Jonathan M Davis wrote: > >>> On

Re: static array with inferred size

2017-09-20 Thread Meta via Digitalmars-d
On Wednesday, 20 September 2017 at 12:41:57 UTC, Stefan Koch wrote: On Wednesday, 20 September 2017 at 12:08:45 UTC, Andrei Alexandrescu wrote: On 09/20/2017 07:49 AM, Jonathan M Davis wrote: On Wednesday, September 20, 2017 10:59:56 Per Nordlöw via Digitalmars-d wrote: On Wednesday, 20

Re: static array with inferred size

2017-09-20 Thread Stefan Koch via Digitalmars-d
On Wednesday, 20 September 2017 at 12:08:45 UTC, Andrei Alexandrescu wrote: On 09/20/2017 07:49 AM, Jonathan M Davis wrote: On Wednesday, September 20, 2017 10:59:56 Per Nordlöw via Digitalmars-d wrote: On Wednesday, 20 September 2017 at 09:13:52 UTC, Jonathan M Davis wrote:

Re: static array with inferred size

2017-09-20 Thread jmh530 via Digitalmars-d
On Wednesday, 20 September 2017 at 12:10:47 UTC, Andrei Alexandrescu wrote: How would this be useful? -- Andrei Really just an additional convenience, instead of writing slice[0..$, 0..$, 0..$, i], you would write slice[.., .., .., i].

Re: static array with inferred size

2017-09-20 Thread Andrei Alexandrescu via Digitalmars-d
On 09/19/2017 11:05 PM, jmh530 wrote: On Wednesday, 20 September 2017 at 02:46:53 UTC, Meta wrote: [snip] I also favor making arr[..] equivalent to arr[0..$] How would this be useful? -- Andrei

Re: static array with inferred size

2017-09-20 Thread Andrei Alexandrescu via Digitalmars-d
On 09/20/2017 07:49 AM, Jonathan M Davis wrote: On Wednesday, September 20, 2017 10:59:56 Per Nordlöw via Digitalmars-d wrote: On Wednesday, 20 September 2017 at 09:13:52 UTC, Jonathan M Davis wrote: https://issues.dlang.org/show_bug.cgi?id=12625 - Jonathan M Davis Looks like we should we

Re: static array with inferred size

2017-09-20 Thread Jonathan M Davis via Digitalmars-d
On Wednesday, September 20, 2017 10:59:56 Per Nordlöw via Digitalmars-d wrote: > On Wednesday, 20 September 2017 at 09:13:52 UTC, Jonathan M Davis > > wrote: > > https://issues.dlang.org/show_bug.cgi?id=12625 > > > > - Jonathan M Davis > > Looks like we should we wait for >

Re: static array with inferred size

2017-09-20 Thread Per Nordlöw via Digitalmars-d
On Wednesday, 20 September 2017 at 09:13:52 UTC, Jonathan M Davis wrote: https://issues.dlang.org/show_bug.cgi?id=12625 - Jonathan M Davis Looks like we should we wait for https://github.com/dlang/dmd/pull/7110 to be merged before adding `s` to druntime.

Re: static array with inferred size

2017-09-20 Thread Jonathan M Davis via Digitalmars-d
On Wednesday, September 20, 2017 08:33:34 Nordlöw via Digitalmars-d wrote: > On Wednesday, 20 September 2017 at 07:38:00 UTC, Jonathan M Davis > > wrote: > > T[n] s(T, size_t n)(auto ref T[n] array) pure nothrow @nogc > > @safe > > { > > > > return array; > > > > } > > What about adding `s` to

Re: static array with inferred size

2017-09-20 Thread Nordlöw via Digitalmars-d
On Wednesday, 20 September 2017 at 08:39:49 UTC, Dgame wrote: Maybe even in object.d so that [1, 2, 3].s is possible without any import. Then it would look like a built-in feature. Good idea. Even better. I'll cook up a druntime-PR.

Re: static array with inferred size

2017-09-20 Thread Dgame via Digitalmars-d
On Wednesday, 20 September 2017 at 08:33:34 UTC, Nordlöw wrote: On Wednesday, 20 September 2017 at 07:38:00 UTC, Jonathan M Davis wrote: T[n] s(T, size_t n)(auto ref T[n] array) pure nothrow @nogc @safe { return array; } What about adding `s` to std.array in the meanwhile? I wonder what

Re: static array with inferred size

2017-09-20 Thread Nordlöw via Digitalmars-d
On Wednesday, 20 September 2017 at 07:38:00 UTC, Jonathan M Davis wrote: T[n] s(T, size_t n)(auto ref T[n] array) pure nothrow @nogc @safe { return array; } What about adding `s` to std.array in the meanwhile? I wonder what Walter says about the static array to slice assignment. Isn't

Re: static array with inferred size

2017-09-20 Thread Jonathan M Davis via Digitalmars-d
On Wednesday, September 20, 2017 07:12:15 Dgame via Digitalmars-d wrote: > On Wednesday, 20 September 2017 at 05:36:43 UTC, Andrei > > Alexandrescu wrote: > > On 9/19/17 8:47 PM, Steven Schveighoffer wrote: > >> This needs to happen. > >> > >> e.g.: > >> > >> char[$] arr = "hello"; // syntax up

Re: static array with inferred size

2017-09-20 Thread Dgame via Digitalmars-d
On Wednesday, 20 September 2017 at 05:36:43 UTC, Andrei Alexandrescu wrote: On 9/19/17 8:47 PM, Steven Schveighoffer wrote: This needs to happen. e.g.: char[$] arr = "hello"; // syntax up for debate, but I like this. I can't think of a correct way to do this that doesn't heap-allocate and

Re: static array with inferred size

2017-09-20 Thread Ilya via Digitalmars-d
On Wednesday, 20 September 2017 at 00:47:25 UTC, Steven Schveighoffer wrote: This needs to happen. e.g.: char[$] arr = "hello"; // syntax up for debate, but I like this. Yes, hope to see this one day as a language feature, not a library solution. --Ilya

Re: static array with inferred size

2017-09-20 Thread Jonathan M Davis via Digitalmars-d
On Wednesday, September 20, 2017 01:36:43 Andrei Alexandrescu via Digitalmars-d wrote: > On 9/19/17 8:47 PM, Steven Schveighoffer wrote: > > This needs to happen. > > > > e.g.: > > > > char[$] arr = "hello"; // syntax up for debate, but I like this. > > > > I can't think of a correct way to do

Re: static array with inferred size

2017-09-19 Thread Andrei Alexandrescu via Digitalmars-d
On 9/19/17 8:47 PM, Steven Schveighoffer wrote: This needs to happen. e.g.: char[$] arr = "hello"; // syntax up for debate, but I like this. I can't think of a correct way to do this that doesn't heap-allocate and is DRY. D is so powerful, it's a huge shame it can't figure this one out.

Re: static array with inferred size

2017-09-19 Thread Steven Schveighoffer via Digitalmars-d
On 9/19/17 10:46 PM, Meta wrote: With all due respect to Andrei, I think he overreacted a bit and it was a mistake to revert static array length deduction (although the array/aa type deduction on steroids was probably overly complicated so that was a good call). Maybe now that @nogc and

Re: static array with inferred size

2017-09-19 Thread jmh530 via Digitalmars-d
On Wednesday, 20 September 2017 at 02:46:53 UTC, Meta wrote: [snip] I also favor making arr[..] equivalent to arr[0..$] and allowing overloading of \ (for inverse, similar syntax as Matlab).

Re: static array with inferred size

2017-09-19 Thread Meta via Digitalmars-d
On Wednesday, 20 September 2017 at 01:29:39 UTC, Jonathan M Davis wrote: On Tuesday, September 19, 2017 20:47:25 Steven Schveighoffer via Digitalmars-d wrote: This needs to happen. e.g.: char[$] arr = "hello"; // syntax up for debate, but I like this. I can't think of a correct way to do

Re: static array with inferred size

2017-09-19 Thread Jonathan M Davis via Digitalmars-d
On Tuesday, September 19, 2017 20:47:25 Steven Schveighoffer via Digitalmars-d wrote: > This needs to happen. > > e.g.: > > char[$] arr = "hello"; // syntax up for debate, but I like this. > > I can't think of a correct way to do this that doesn't heap-allocate and > is DRY. > > D is so powerful,

static array with inferred size

2017-09-19 Thread Steven Schveighoffer via Digitalmars-d
This needs to happen. e.g.: char[$] arr = "hello"; // syntax up for debate, but I like this. I can't think of a correct way to do this that doesn't heap-allocate and is DRY. D is so powerful, it's a huge shame it can't figure this one out. issue: