Re: C# 7 Features - Tuples
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.
Re: C# 7 Features - Tuples
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); }
Re: C# 7 Features - Tuples
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.
Re: C# 7 Features - Tuples
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".
Re: C# 7 Features - Tuples
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/ came across the new c# features today. I really liked the 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.
Re: C# 7 Features - Tuples
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/ubrngkdmyduepmfkh...@forum.dlang.org
Re: C# 7 Features - Tuples
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"
Re: C# 7 Features - Tuples
On 25.08.2016 16:43, Dominikus Dittes Scherkl wrote: 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/ came across the new c# features today. I really liked the 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(); I don't understand. What is the issue here?
Re: C# 7 Features - Tuples
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/DIP32 I like DIP32, but I wouldn't be that bothered if it took until 2018 to get something like it in D.
Re: C# 7 Features - Tuples
On Thursday, 25 August 2016 at 15:02:06 UTC, Steven Schveighoffer wrote: On 8/25/16 10:43 AM, Dominikus Dittes Scherkl wrote: 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/ came across the new c# features today. I really liked the 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? It was *just* deprecated, I don't think even in a released version yet! -Steve 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/DIP32
Re: C# 7 Features - Tuples
On 8/25/16 10:43 AM, Dominikus Dittes Scherkl wrote: 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/ came across the new c# features today. I really liked the 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? It was *just* deprecated, I don't think even in a released version yet! -Steve
Re: C# 7 Features - Tuples
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/ came across the new c# features today. I really liked the 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();
Re: C# 7 Features - Tuples
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/ came across the new c# features today. I really liked the syntax for Tuples (and deconstructors), would be great to have a similar syntax in D :) Yeah, it's looks very cool!
C# 7 Features - Tuples
https://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/ came across the new c# features today. I really liked the syntax for Tuples (and deconstructors), would be great to have a similar syntax in D :)