Re: Arrays, garbage collection

2015-01-31 Thread Andrei Alexandrescu via Digitalmars-d
On 1/31/15 1:10 AM, Martin Nowak wrote: Thanks for this code, it's a lot nicer and simpler than mine. -- Andrei So, pull request for std.array and reverting the dollar thingie? Problem solved? This looks like the way to go. I apologize to the community for the indecision shown. -- Andrei

Re: Arrays, garbage collection

2015-01-31 Thread Martin Nowak via Digitalmars-d
Thanks for this code, it's a lot nicer and simpler than mine. -- Andrei So, pull request for std.array and reverting the dollar thingie? Problem solved?

Re: Arrays, garbage collection

2015-01-31 Thread Walter Bright via Digitalmars-d
On 1/31/2015 8:08 AM, Andrei Alexandrescu wrote: On 1/31/15 1:10 AM, Martin Nowak wrote: Thanks for this code, it's a lot nicer and simpler than mine. -- Andrei So, pull request for std.array and reverting the dollar thingie? Problem solved? This looks like the way to go. I apologize to the

Re: Arrays, garbage collection

2015-01-30 Thread Walter Bright via Digitalmars-d
On 1/30/2015 6:54 AM, Andrei Alexandrescu wrote: On 1/30/15 1:29 AM, Foo wrote: Thanks for this code, it's a lot nicer and simpler than mine. -- Andrei I'm going to swipe this for an upcoming presentation I'm doing. Thanks, Foo!

Re: Arrays, garbage collection

2015-01-30 Thread Namespace via Digitalmars-d
On Friday, 30 January 2015 at 22:21:15 UTC, Walter Bright wrote: On 1/30/2015 6:54 AM, Andrei Alexandrescu wrote: On 1/30/15 1:29 AM, Foo wrote: Thanks for this code, it's a lot nicer and simpler than mine. -- Andrei I'm going to swipe this for an upcoming presentation I'm doing. Thanks,

Re: Arrays, garbage collection

2015-01-30 Thread Andrei Alexandrescu via Digitalmars-d
On 1/30/15 1:29 AM, Foo wrote: @nogc @safe T[n] s(T = Args[0], size_t n = Args.length, Args...)(auto ref Args args) pure nothrow { return [args]; } @nogc @safe T[n] s(T, size_t n)(auto ref T[n] values) pure nothrow { return values; } void main() { pragma(msg, typeof(s(1, 2,

Re: Arrays, garbage collection

2015-01-30 Thread Daniel Kozak via Digitalmars-d
On Friday, 30 January 2015 at 08:54:55 UTC, bearophile wrote: Daniel Kozák: No, it makes more bugs possible // this is compile error so its ok int[MUST_HAVE_FIVE_ITEMS] a=[1,2,3,5]; // Error: mismatched array lengths, 5 and 4 Have you tried to compile my code? It doesn't give an error.

Re: Arrays, garbage collection

2015-01-30 Thread bearophile via Digitalmars-d
Andrei Alexandrescu: No, we need to define a function for that - please file an enhancement request, thanks. -- Andrei No, the enhancement is in Bugzilla since lot of time. But it's for a built-in syntax. A function name is too much long, and when the inlining is switched off it makes the

Re: Arrays, garbage collection

2015-01-30 Thread bearophile via Digitalmars-d
deadalnix: - added optimization to promote them on heap. Thing like int[2] = [1, 2] can trivially avoid GC allocation. See my usage examples (think of the examples as not having the s suffix): void main() { // Some imports here. foo([[1, 2]s, [3, 4]]s); auto t1 = tuple([1,

Re: Arrays, garbage collection

2015-01-30 Thread Foo via Digitalmars-d
On Friday, 30 January 2015 at 01:08:31 UTC, bearophile wrote: The D type inference for array literals is now more flexible: void main() { auto[$][$] m1 = [[1, 2], [3, 4], [5, 6]]; pragma(msg, typeof(m1)); // int[2][3] const auto[string] aa1 = [red: 1, blue: 2]; pragma(msg,

Re: Arrays, garbage collection

2015-01-30 Thread bearophile via Digitalmars-d
Daniel Kozák: No, it makes more bugs possible // this is compile error so its ok int[MUST_HAVE_FIVE_ITEMS] a=[1,2,3,5]; // Error: mismatched array lengths, 5 and 4 Have you tried to compile my code? It doesn't give an error. Bye, bearophile

Re: Arrays, garbage collection

2015-01-30 Thread via Digitalmars-d
On Friday, 30 January 2015 at 07:37:07 UTC, Daniel Kozák wrote: V Fri, 30 Jan 2015 01:08:30 + bearophile via Digitalmars-d digitalmars-d@puremagic.com napsáno: It helps avoid bugs like: int[5] a = [1,2,4,5]; No, it makes more bugs possible // this is compile error so its ok

Arrays, garbage collection

2015-01-29 Thread bearophile via Digitalmars-d
The D type inference for array literals is now more flexible: void main() { auto[$][$] m1 = [[1, 2], [3, 4], [5, 6]]; pragma(msg, typeof(m1)); // int[2][3] const auto[string] aa1 = [red: 1, blue: 2]; pragma(msg, typeof(aa1)); // const(int)[string] } It helps avoid bugs like:

Re: Arrays, garbage collection

2015-01-29 Thread Andrei Alexandrescu via Digitalmars-d
On 1/29/15 5:08 PM, bearophile wrote: What's missing is a handy and compiler-efficient syntax to create value array literals. Some persons have proposed the []s syntax: No, we need to define a function for that - please file an enhancement request, thanks. -- Andrei

Re: Arrays, garbage collection

2015-01-29 Thread deadalnix via Digitalmars-d
On Friday, 30 January 2015 at 02:08:23 UTC, Andrei Alexandrescu wrote: On 1/29/15 5:08 PM, bearophile wrote: What's missing is a handy and compiler-efficient syntax to create value array literals. Some persons have proposed the []s syntax: No, we need to define a function for that - please

Re: Arrays, garbage collection

2015-01-29 Thread Daniel Kozák via Digitalmars-d
V Fri, 30 Jan 2015 01:08:30 + bearophile via Digitalmars-d digitalmars-d@puremagic.com napsáno: It helps avoid bugs like: int[5] a = [1,2,4,5]; No, it makes more bugs possible // this is compile error so its ok int[MUST_HAVE_FIVE_ITEMS] a=[1,2,3,5]; // Error: mismatched array