digitalmars.D.bugs - [Issue 9120] New: Uniform construction for array types
- d-bugmail puremagic.com (41/41) Dec 06 2012 http://d.puremagic.com/issues/show_bug.cgi?id=9120
- d-bugmail puremagic.com (25/25) Dec 06 2012 http://d.puremagic.com/issues/show_bug.cgi?id=9120
- d-bugmail puremagic.com (10/31) Dec 06 2012 http://d.puremagic.com/issues/show_bug.cgi?id=9120
http://d.puremagic.com/issues/show_bug.cgi?id=9120 Summary: Uniform construction for array types Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: k.hara.pg gmail.com --- Comment #0 from Kenji Hara <k.hara.pg gmail.com> 2012-12-06 16:51:45 PST --- Spin-off issue from bug 9112. In current, array types does not have consistency between literal syntax and `new` syntax. void maiin() { // dynamic array int[] da1 = [1,2,3]; // literal syntax //int[] da2 = int[](1,2,3); // not allowed // because dynamic array is *always* allocated in heap? int[] da3 = new int[](3); // heap-allocated int array has length 3. // but, all elements in da2 initialized with int.init. // we cannot give initializing elements in use of new syntax. int[] dax = new int[3]; // special syntax. This creates int[] has length 3. int[3] sa1 = [1,2,3]; // literal syntax //int[3] sa2 = int[3](1,2,3); // not allowed //int[3]* sa3a = new int[3]; // impossible alias T = int[3]; //int[3]* sa3b = new T;. // Error: new can only create structs, dynamic arrays or class objects, not int[3u]'s // -> special syntax for dynamic array blocks this... int[string] aa1 = ["a":1, "b":2]; // literal syntax //int[string] aa1 = int[string]("a":1, "b":2); // not allowed //int[string] aa2 = new int[string]; // not allowed } This is not serious language flaw, but I feel it is desirable which have consistent syntax. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 06 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9120 bearophile_hugs eml.cc changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bearophile_hugs eml.cc --- Comment #1 from bearophile_hugs eml.cc 2012-12-06 18:05:57 PST --- What exactly are the syntax changes/additions are you suggesting? I think this syntax is better to not support this syntax: int[] da2 = int[](1,2,3); // not allowed ------------------- There are several design problems in the array syntax. Like: Issue 3849 Issue 4703 Issue 7445 One maybe even bigger syntax problem is related to mixing fixed-sized arrays and dynamic arrays. This is not supported (this means a dynamic array of fixed arrays of dynamic arrays): void main() { auto a = new int[][3][](5, 7); } Currently the D syntax to create such mixes is incomplete, and I think it's not clear enough. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 06 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9120 --- Comment #2 from Kenji Hara <k.hara.pg gmail.com> 2012-12-06 18:45:36 PST --- (In reply to comment #1)What exactly are the syntax changes/additions are you suggesting?I'm not sure what is should be chosen. This is not an exact syntax proposal, rather a suggestion to discuss about the issue.I think this syntax is better to not support this syntax: int[] da2 = int[](1,2,3); // not allowedI agree that supporting it (stack-allocated dynamic array) is much difficult.There are several design problems in the array syntax. Like: Issue 3849 Issue 4703 Issue 7445 One maybe even bigger syntax problem is related to mixing fixed-sized arrays and dynamic arrays. This is not supported (this means a dynamic array of fixed arrays of dynamic arrays): void main() { auto a = new int[][3][](5, 7); } Currently the D syntax to create such mixes is incomplete, and I think it's not clear enough.Thanks for presenting related issues. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 06 2012