Thread overview | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 25, 2016 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 :) |
August 25, 2016 Re: C# 7 Features - Tuples | ||||
---|---|---|---|---|
| ||||
Posted in reply to dom | 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!
|
August 25, 2016 Re: C# 7 Features - Tuples | ||||
---|---|---|---|---|
| ||||
Posted in reply to dom | 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();
|
August 25, 2016 Re: C# 7 Features - Tuples | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dominikus Dittes Scherkl | 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
|
August 25, 2016 Re: C# 7 Features - Tuples | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | 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 |
August 25, 2016 Re: C# 7 Features - Tuples | ||||
---|---|---|---|---|
| ||||
Posted in reply to Seb | 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.
|
August 25, 2016 Re: C# 7 Features - Tuples | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dominikus Dittes Scherkl | 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"
|
August 25, 2016 Re: C# 7 Features - Tuples | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dominikus Dittes Scherkl | 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?
|
August 26, 2016 Re: C# 7 Features - Tuples | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dominikus Dittes Scherkl | 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 |
August 26, 2016 Re: C# 7 Features - Tuples | ||||
---|---|---|---|---|
| ||||
Posted in reply to dom | 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.
|
Copyright © 1999-2021 by the D Language Foundation