July 23, 2011 [Issue 6365] New: AutoTupleDeclaration | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=6365 Summary: AutoTupleDeclaration 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> 2011-07-23 05:00:58 PDT --- Syntax: 'auto' '(' Identifier [',' Identifier ...] ')' '=' Initializer ';' Example: auto (num, msg) = TypeTuple!(1, "hello"); // built-in tuple assert(num == 1); assert(msg == "hello"); auto (name, age) = tuple("John", 10); // library tuple (= alias this tuple) assert(name == "John"); assert(age == 10); auto (n1, n2) = 100; // non tuple initializer assert(n1 == 100); assert(n2 == 100); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
July 23, 2011 [Issue 6365] AutoTupleDeclaration | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kenji Hara | http://d.puremagic.com/issues/show_bug.cgi?id=6365 --- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2011-07-23 05:08:51 PDT --- Also we can allow a static array on initializer like follows: auto (x, y) = [10, 20]; assert(x == 10); assert(y == 20); But, it has a bit problem. auto (x, y) = [10, 20, 30]; // interpreted as non tuple initializer assert(x == [10, 20, 30]); assert(y == [10, 20, 30]); auto (x, y) = [10]; // interpreted as non tuple initializer assert(x == [10]); assert(y == [10]); It is not inconsistent, but less useful. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
July 23, 2011 [Issue 6365] AutoTupleDeclaration | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kenji Hara | http://d.puremagic.com/issues/show_bug.cgi?id=6365 bearophile_hugs@eml.cc changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bearophile_hugs@eml.cc --- Comment #2 from bearophile_hugs@eml.cc 2011-07-23 05:14:44 PDT --- (In reply to comment #0) > auto (n1, n2) = 100; // non tuple initializer > assert(n1 == 100); > assert(n2 == 100); This *must* be a compile-time error. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
July 23, 2011 [Issue 6365] AutoTupleDeclaration | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kenji Hara | http://d.puremagic.com/issues/show_bug.cgi?id=6365 --- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> 2011-07-23 05:17:57 PDT --- (In reply to comment #2) > (In reply to comment #0) > > > auto (n1, n2) = 100; // non tuple initializer > > assert(n1 == 100); > > assert(n2 == 100); > > This *must* be a compile-time error. This is keeping consistent feature. Current D allow compilation of following code: TypeTuple!(int, int) f = 10; assert(f[0] == 10); assert(f[1] == 10); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
July 23, 2011 [Issue 6365] AutoTupleDeclaration | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kenji Hara | http://d.puremagic.com/issues/show_bug.cgi?id=6365 --- Comment #4 from bearophile_hugs@eml.cc 2011-07-23 05:18:55 PDT --- Optionally there is the foreach use case too. A possible syntax: auto array = [tuple(1,"foo"), tuple(2,"bar")]; foreach (tuple(id, name); array) {} -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
July 23, 2011 [Issue 6365] AutoTupleDeclaration | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kenji Hara | http://d.puremagic.com/issues/show_bug.cgi?id=6365 --- Comment #5 from bearophile_hugs@eml.cc 2011-07-23 05:23:06 PDT --- (In reply to comment #3) > This is keeping consistent feature. > Current D allow compilation of following code: > > TypeTuple!(int, int) f = 10; > assert(f[0] == 10); > assert(f[1] == 10); I didn't know this, thank you. So the semantics of TypeTuple is broken. This design mistake must not be carried over to Tuples too. Consistancy with a so wrong design is like shooting yourself in the foot and makes this whole enhancement request of negative value. It's better to fix this TypeTuple design bug instead. I will file an enhancement request on it. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
July 23, 2011 [Issue 6365] AutoTupleDeclaration | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kenji Hara | http://d.puremagic.com/issues/show_bug.cgi?id=6365 --- Comment #6 from Kenji Hara <k.hara.pg@gmail.com> 2011-07-23 05:27:14 PDT --- (In reply to comment #4) > Optionally there is the foreach use case too. A possible syntax: > > auto array = [tuple(1,"foo"), tuple(2,"bar")]; > foreach (tuple(id, name); array) {} I filed an issue about alias this + foreach range.front behavior. http://d.puremagic.com/issues/show_bug.cgi?id=6366 Please comment there. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
July 23, 2011 [Issue 6365] AutoTupleDeclaration | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kenji Hara | http://d.puremagic.com/issues/show_bug.cgi?id=6365 Andrei Alexandrescu <andrei@metalanguage.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |andrei@metalanguage.com --- Comment #7 from Andrei Alexandrescu <andrei@metalanguage.com> 2011-07-23 07:32:23 PDT --- One simple syntactic matter is that we can't extend the existing syntax to work with specified types. That means the user must use "auto" but cannot specify the types of the variables defined. To allow that in the future, we need to move the paren before the auto: (auto i, j) = tuple(1.2, "a"); Then the syntax can be later extended to: (double i, string j) = tuple(1.2, "a"); Anyway, we should wait for Walter to weigh in. Thanks Kenji for this work. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
July 23, 2011 [Issue 6365] AutoTupleDeclaration | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kenji Hara | http://d.puremagic.com/issues/show_bug.cgi?id=6365 --- Comment #8 from Andrei Alexandrescu <andrei@metalanguage.com> 2011-07-23 07:33:33 PDT --- Regarding mismatch in the number of elements, we may actually do good to disable TypeTuple!(int, int) f = 10; assert(f[0] == 10); assert(f[1] == 10); instead of striving to be consistent with it. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
July 23, 2011 [Issue 6365] AutoTupleDeclaration | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kenji Hara | http://d.puremagic.com/issues/show_bug.cgi?id=6365 --- Comment #9 from bearophile_hugs@eml.cc 2011-07-23 07:48:46 PDT --- (In reply to comment #8) > Regarding mismatch in the number of elements, we may actually do good to disable > > TypeTuple!(int, int) f = 10; > assert(f[0] == 10); > assert(f[1] == 10); > > instead of striving to be consistent with it. This was right my point. On this I have opened bug 6367 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation