Re: More useful fixed-size array literals

2014-05-30 Thread Meta via Digitalmars-d
On Friday, 30 May 2014 at 22:19:51 UTC, bearophile wrote: Code similar to this is not uncommon. Currently it's refused: immutable data = [1, 5, 3, 1, 5, 1, 5]; void main() @nogc { import std.algorithm: count; assert(data.count([1, 5]) == 3); } test.d(4,23): Error: array literal in @no

Re: More useful fixed-size array literals

2014-05-30 Thread bearophile via Digitalmars-d
Meta: What about prepending the word static? immutable data = [1, 5, 3, 1, 5, 1, 5]; void main() @nogc { import std.algorithm: count; assert(data.count(static[1, 5]) == 3); } This is about the same as appending the char 's'. Or variadic template arguments. Aren't they allocated on t

Re: More useful fixed-size array literals

2014-05-30 Thread Mason McGill via Digitalmars-d
On Friday, 30 May 2014 at 22:19:51 UTC, bearophile wrote: A language solution is a literal syntax for fixed-sized arrays (here I slice it again because unfortunately count doesn't accept fixed-sized arrays): immutable data = [1, 5, 3, 1, 5, 1, 5]; void main() @nogc { import std.algorithm:

Re: More useful fixed-size array literals

2014-05-30 Thread Benjamin Thaut via Digitalmars-d
Am 31.05.2014 00:19, schrieb bearophile: Code similar to this is not uncommon. Currently it's refused: immutable data = [1, 5, 3, 1, 5, 1, 5]; void main() @nogc { import std.algorithm: count; assert(data.count([1, 5]) == 3); } test.d(4,23): Error: array literal in @nogc function mai

Re: More useful fixed-size array literals

2014-05-31 Thread Namespace via Digitalmars-d
I remember Kenji is not fond of this []s syntax, for reasons I don't remember. Do you think there are other better/different solutions? Bye, bearophile Read it on my closed Pull Request: https://github.com/D-Programming-Language/dmd/pull/2952 Another attempt was also closed: https://github.c

Re: More useful fixed-size array literals

2014-05-31 Thread bearophile via Digitalmars-d
Benjamin Thaut: give "scope" a meaning for function arguments other then lambdas E.g: size_t count(scope int[] heystack, scope int[] needle); Now the compiler can allocate the literal [1, 5] on the stack without any special syntax because it knows that the array literal will not be escaped.

Re: More useful fixed-size array literals

2014-05-31 Thread bearophile via Digitalmars-d
int foo(scope int[] items) @nogc { return foo.sum; } That was: return items.sum; Bye, bearophile

Re: More useful fixed-size array literals

2014-05-31 Thread Benjamin Thaut via Digitalmars-d
Am 31.05.2014 11:08, schrieb bearophile: int foo(scope int[] items) @nogc { return foo.sum; } That was: return items.sum; Bye, bearophile Well obviously the std.algorithm sum would also be annoted with scope. Because it doesn't escape it either. I don't see the problem here. And in ca

Re: More useful fixed-size array literals

2014-05-31 Thread bearophile via Digitalmars-d
Benjamin Thaut: Well obviously the std.algorithm sum would also be annoted with scope. Because it doesn't escape it either. I don't see the problem here. And in case you really want to escape it, you need to .dup it. A additional advantage of my solution is, that the compiler can prove it t

Re: More useful fixed-size array literals

2014-06-03 Thread bearophile via Digitalmars-d
Namespace: Another attempt was also closed: https://github.com/D-Programming-Language/dmd/pull/2958 There is a good hope: https://github.com/D-Programming-Language/dmd/pull/3615 Bye, bearophile