digitalmars.D - C# 7 Features - Tuples
- dom (4/4) Aug 25 2016 https://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7...
- Suliman (2/6) Aug 25 2016 Yeah, it's looks very cool!
- Dominikus Dittes Scherkl (13/17) Aug 25 2016 Pretty obvious syntax, but would require the comma operator to be
- Steven Schveighoffer (3/13) Aug 25 2016 It was *just* deprecated, I don't think even in a released version yet!
- Seb (11/30) Aug 25 2016 Yep,
- jmh530 (3/11) Aug 25 2016 I like DIP32, but I wouldn't be that bothered if it took until
- rumbu (14/23) Aug 25 2016 This is possible:
- Timon Gehr (2/21) Aug 25 2016 I don't understand. What is the issue here?
- Kagamin (4/11) Aug 26 2016 See
- Cauterite (5/11) Aug 26 2016 Because how are you supposed to know what each member of the
- Nick Treleaven (9/16) Sep 05 2016 Another solution is to support out argument declarations, as they
- Lodovico Giaretta (24/32) Sep 05 2016 We can already (almost do that):
- Nick Treleaven (7/31) Sep 06 2016 The main benefit of supporting tuple syntax is unpacking into new
- ixid (7/11) Aug 26 2016 This is fantastic, hopefully we can have this syntax in
https://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/ for Tuples (and deconstructors), would be great to have a similar syntax in D :)
Aug 25 2016
On Thursday, 25 August 2016 at 13:41:29 UTC, dom wrote:https://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/ syntax for Tuples (and deconstructors), would be great to have a similar syntax in D :)Yeah, it's looks very cool!
Aug 25 2016
On Thursday, 25 August 2016 at 13:41:29 UTC, dom wrote:https://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/ syntax for Tuples (and deconstructors), would be great to have a similar syntax in D :)Pretty obvious syntax, but would require the comma operator to be removed. Isn't it deprecated long enough meanwhile, so we finally can kill it? But I dislike the named tuple members. Why not declare them at the calling site? (int, int, int, string) fn() { return (3, 2, 1, "meins"); } int x, y, z; string s; (x, y, z, s) = fn();
Aug 25 2016
On 8/25/16 10:43 AM, Dominikus Dittes Scherkl wrote:On Thursday, 25 August 2016 at 13:41:29 UTC, dom wrote:It was *just* deprecated, I don't think even in a released version yet! -Stevehttps://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/ Tuples (and deconstructors), would be great to have a similar syntax in D :)Pretty obvious syntax, but would require the comma operator to be removed. Isn't it deprecated long enough meanwhile, so we finally can kill it?
Aug 25 2016
On Thursday, 25 August 2016 at 15:02:06 UTC, Steven Schveighoffer wrote:On 8/25/16 10:43 AM, Dominikus Dittes Scherkl wrote:Yep, https://dlang.org/deprecate.html#Using%20the%20result%20of%20a%20comma%20expression https://github.com/dlang/dmd/pull/5737 However working out the rules and changes for a Tuple syntax would be a great topic for a DIP: https://github.com/dlang/DIPs Btw there has been previous work on this topic, so this could be used as a base: https://wiki.dlang.org/DIP32On Thursday, 25 August 2016 at 13:41:29 UTC, dom wrote:It was *just* deprecated, I don't think even in a released version yet! -Stevehttps://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/ syntax for Tuples (and deconstructors), would be great to have a similar syntax in D :)Pretty obvious syntax, but would require the comma operator to be removed. Isn't it deprecated long enough meanwhile, so we finally can kill it?
Aug 25 2016
On Thursday, 25 August 2016 at 15:50:09 UTC, Seb wrote:https://dlang.org/deprecate.html#Using%20the%20result%20of%20a%20comma%20expression https://github.com/dlang/dmd/pull/5737 However working out the rules and changes for a Tuple syntax would be a great topic for a DIP: https://github.com/dlang/DIPs Btw there has been previous work on this topic, so this could be used as a base: https://wiki.dlang.org/DIP32I like DIP32, but I wouldn't be that bothered if it took until 2018 to get something like it in D.
Aug 25 2016
On Thursday, 25 August 2016 at 14:43:35 UTC, Dominikus Dittes Scherkl wrote:But I dislike the named tuple members. Why not declare them at the calling site? (int, int, int, string) fn() { return (3, 2, 1, "meins"); } int x, y, z; string s; (x, y, z, s) = fn();This is possible: " (string, string, string) LookupName(long id) // tuple return type { ... // retrieve first, middle and last from data storage return (first, middle, last); // tuple literal } ... "You can also deconstruct into existing variables with a deconstructing assignment: (first, middle, last) = LookupName(id2); // deconstructing assignment"
Aug 25 2016
On 25.08.2016 16:43, Dominikus Dittes Scherkl wrote:On Thursday, 25 August 2016 at 13:41:29 UTC, dom wrote:I don't understand. What is the issue here?https://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/ Tuples (and deconstructors), would be great to have a similar syntax in D :)Pretty obvious syntax, but would require the comma operator to be removed. Isn't it deprecated long enough meanwhile, so we finally can kill it? But I dislike the named tuple members. Why not declare them at the calling site? (int, int, int, string) fn() { return (3, 2, 1, "meins"); } int x, y, z; string s; (x, y, z, s) = fn();
Aug 25 2016
On Thursday, 25 August 2016 at 14:43:35 UTC, Dominikus Dittes Scherkl wrote:(int, int, int, string) fn() { return (3, 2, 1, "meins"); } int x, y, z; string s; (x, y, z, s) = fn();See https://forum.dlang.org/post/ubrngkdmyduepmfkhefp forum.dlang.org
Aug 26 2016
On Thursday, 25 August 2016 at 14:43:35 UTC, Dominikus Dittes Scherkl wrote:But I dislike the named tuple members. Why not declare them at the calling site? (int, int, int, string) fn() { return (3, 2, 1, "meins"); }Because how are you supposed to know what each member of the tuple represents? If you read the function signature all you see is "int, int, int, string".
Aug 26 2016
On Thursday, 25 August 2016 at 14:43:35 UTC, Dominikus Dittes Scherkl wrote:(int, int, int, string) fn() { return (3, 2, 1, "meins"); } int x, y, z; string s; (x, y, z, s) = fn();Another solution is to support out argument declarations, as they are a more general feature. These could then be used as follows: Tuple!(int, string) fn(); void unpack(T...)(Tuple!T, out T decls); // new phobos function fn().unpack(int i, string s); I think a combination of tuple slicing and unpack() overloads could allow ignoring leading or trailing tuple fields.
Sep 05 2016
On Monday, 5 September 2016 at 15:43:43 UTC, Nick Treleaven wrote:Another solution is to support out argument declarations, as they are a more general feature. These could then be used as follows: Tuple!(int, string) fn(); void unpack(T...)(Tuple!T, out T decls); // new phobos function fn().unpack(int i, string s); I think a combination of tuple slicing and unpack() overloads could allow ignoring leading or trailing tuple fields.We can already (almost do that): ======================================================== import std.stdio, std.typecons; void unpack(T...)(Tuple!T tup, out T decls) { static if (tup.length > 0) { decls[0] = tup[0]; tuple(tup[1..$]).unpack(decls[1..$]); } } void main() { auto t = tuple(1, "a", 3.0); int i; string s; double d; t.unpack(i, s, d); writeln(i); writeln(s); writeln(d); } ========================================================
Sep 05 2016
On Monday, 5 September 2016 at 15:50:31 UTC, Lodovico Giaretta wrote:On Monday, 5 September 2016 at 15:43:43 UTC, Nick Treleaven wrote: We can already (almost do that): ======================================================== import std.stdio, std.typecons; void unpack(T...)(Tuple!T tup, out T decls) { static if (tup.length > 0) { decls[0] = tup[0]; tuple(tup[1..$]).unpack(decls[1..$]); } } void main() { auto t = tuple(1, "a", 3.0); int i; string s; double d; t.unpack(i, s, d); writeln(i); writeln(s); writeln(d); }The main benefit of supporting tuple syntax is unpacking into new declarations (writing Tuple!(...) or tuple!(...) isn't that significant IMO). I was suggesting that out argument *declarations* actually provides this and is a more general feature.
Sep 06 2016
On Thursday, 25 August 2016 at 13:41:29 UTC, dom wrote:https://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/ syntax for Tuples (and deconstructors), would be great to have a similar syntax in D :)This is fantastic, hopefully we can have this syntax in D.Ultimately it would be nice if we could move towards the rest of the C-style tidy ups that are becoming more commonly used but I know this community is pretty conservative. Optional semi-colons, no parens on if, while etc and enforced curly braces. Also := being a synonym for auto assignment.
Aug 26 2016