digitalmars.dip.ideas - Tuple Unpacking Syntax
- Meta (22/22) May 12 This DIP proposes built-in tuple unpacking syntax for D. A sample
- Meta (2/2) May 12 Apologies to Nick _Treleaven_ as I misspelled his name in my
- Adam D. Ruppe (4/6) May 12 Note that this has been implemented and shipped in OpenD for a
- Meta (3/9) May 12 Very nice, I didn't know that. Is that using Timon's
- Adam D. Ruppe (3/5) May 12 Yes, he helped prepare it and we merged as soon as it was ready.
- monkyyy (25/30) May 12 Make overflowing assignments landmines rather then errors?
- jmh530 (7/29) May 12 In your rationale, you provide an example of how it works
- Meta (3/10) May 12 Yup, that's right.
- Nick Treleaven (4/9) Jun 02 For the record, Meta added an example with unpacking syntax for
- jmh530 (2/12) Jun 02 Yeah, I had seen that. Nice improvement to the DIP.
- Sergey (7/9) May 13 Awesome DIP!
- Meta (2/11) May 13 I'm pretty sure that works, except it should be [0.1, 0.2, 0.3].
- Timon Gehr (6/21) May 14 Has to be `[0.1, 0.2, 0.3].staticArray` actually, as there is no reverse...
- Nick Treleaven (6/17) May 15 Either of these seem to work with the unpacking branch:
- Timon Gehr (39/58) May 15 You are correct. I did not take into account that this works:
- Ogion (6/14) May 20 The next logical step after this DIP is to enable initialization
- Nick Treleaven (13/18) Jun 02 Firstly, from the left-hand side, that is not tuple
- jmh530 (3/6) May 14 Typo in one of the headers for the "Grammar Changes" section:
- Nick Treleaven (3/10) May 15 Thanks, PR:
- jmh530 (8/11) May 14 If D adds built-in tuples in the future, would `.tupleof` be part
- Meta (5/17) May 14 Funny you should mention that. I suggested the exact same thing
- Timon Gehr (12/26) May 14 `.tupleof` in general is a low-level primitive that gives you a built-in...
- jmh530 (7/19) May 15 In the back of my head I recall people complaining about some
- Nick Treleaven (2/4) May 15 The hard work was all Timon's ;-)
- jmh530 (25/47) May 20 Let's say you have
- Timon Gehr (5/11) May 20 a) With C-style conventions, `int (a, b)` would say: we declare that the...
- jmh530 (11/23) May 21 On a), the DMD compiler won't let you write `int (a, b);` It
- Timon Gehr (16/44) Jun 01 This is not what it would lower to, a method call cannot declare free
- Atila Neves (2/7) Jun 02 Why not a full tuple DIP?
- Meta (4/12) Jun 02 I discussed it with Timon and Nick, but we decided to limit the
- Timon Gehr (30/39) Jun 05 Unpacking is the biggest tuple-related omission in D's current feature
- M. M. (5/11) Jun 05 I just hope you relevant people can get some good discussion on
- Atila Neves (2/8) Jun 12 Ok, thanks.
This DIP proposes built-in tuple unpacking syntax for D. A sample of the proposed syntax: ```d import std.typecons : tuple; (int a, string b) = tuple(1, "2"); assert(a == 1); assert(b == "2"); auto (a, b) = tuple(1, "2"); static assert(is(typeof(a) == int)); static assert(is(typeof(b) == string)); auto (a, immutable b, c) = tuple(1, "2", 3.0); static assert(is(typeof(a) == int)); static assert(is(typeof(b) == immutable string)); static assert(is(typeof(c) == double)); ``` The DIP is based on Timon Gehr's old DIP for tuple syntax in D (https://github.com/tgehr/DIPs/blob/tuple-syntax/DIPs/DIP1xxx-tg.md), but is solely limited to support for unpacking; **it is not a full tuple-syntax DIP**. If the reception and general sentiment for this DIP are positive, further enhancements to add built-in tuple support to D may be proposed in the future. Thanks to Timon and Nick Trealeven for doing the bulk of the implementation and conceptual work on this proposal. I mainly just kickstarted things and am facilitating the DIP process. The DIP: https://github.com/MetaLang/DIPs/blob/tuple-unpacking-dip/DIPs/DIP1052.md
May 12
Apologies to Nick _Treleaven_ as I misspelled his name in my post; unfortunately, it can't be edited.
May 12
On Monday, 12 May 2025 at 23:01:54 UTC, Meta wrote:This DIP proposes built-in tuple unpacking syntax for D. A sample of the proposed syntax:Note that this has been implemented and shipped in OpenD for a long time, many months. Your example works with the opend compiler right now; https://opendlang.org/start.html
May 12
On Monday, 12 May 2025 at 23:35:06 UTC, Adam D. Ruppe wrote:On Monday, 12 May 2025 at 23:01:54 UTC, Meta wrote:Very nice, I didn't know that. Is that using Timon's implementation?This DIP proposes built-in tuple unpacking syntax for D. A sample of the proposed syntax:Note that this has been implemented and shipped in OpenD for a long time, many months. Your example works with the opend compiler right now; https://opendlang.org/start.html
May 12
On Monday, 12 May 2025 at 23:36:26 UTC, Meta wrote:Very nice, I didn't know that. Is that using Timon's implementation?Yes, he helped prepare it and we merged as soon as it was ready. Caused virtually zero breakage, so easy addition.
May 12
On Monday, 12 May 2025 at 23:01:54 UTC, Meta wrote:This DIP proposes built-in tuple unpacking syntax for D. A sample of the proposed syntax: ```d import std.typecons : tuple; (int a, string b) = tuple(1, "2");Make overflowing assignments landmines rather then errors? ```d auto foo(T)(T t){ auto (a,b,c)=t; static if(T.length>2){ return c; } else { return a; }} unittest{ assert(foo(tuple(1,'b',"c"))=="c"); assert(foo(tuple(1))==1); } auto bar(T)(T t){ auto (a,b,c)=t; return c; } unittest{ assert(foo(tuple(1,'b',"c"))=="c"); assert(foo(tuple(1))==1);//fails `Error: tuple!int was split into 3 fields but only has 1, then `c` used on line 15 in bar!(tuple!int) } ```
May 12
On Monday, 12 May 2025 at 23:01:54 UTC, Meta wrote:This DIP proposes built-in tuple unpacking syntax for D. A sample of the proposed syntax: ```d import std.typecons : tuple; (int a, string b) = tuple(1, "2"); assert(a == 1); assert(b == "2"); auto (a, b) = tuple(1, "2"); static assert(is(typeof(a) == int)); static assert(is(typeof(b) == string)); auto (a, immutable b, c) = tuple(1, "2", 3.0); static assert(is(typeof(a) == int)); static assert(is(typeof(b) == immutable string)); static assert(is(typeof(c) == double)); ``` The DIP is based on Timon Gehr's old DIP for tuple syntax in (https://github.com/tgehr/DIPs/blob/tuple-syntax/DIPs/DIP1xxx-tg.md), but is solely limited to support for unpacking; **it is not a full tuple-syntax DIP**. If the reception and general sentiment for this DIP are positive, further enhancements to add built-in tuple support to D may be proposed in the future. Thanks to Timon and Nick Trealeven for doing the bulk of the implementation and conceptual work on this proposal. I mainly just kickstarted things and am facilitating the DIP process. The DIP: https://github.com/MetaLang/DIPs/blob/tuple-unpacking-dip/DIPs/DIP1052.mdIn your rationale, you provide an example of how it works currently. You might show how it works with the DIP as well as a contrast. Am I right that any function that returns a tuple can use it like ‘auto (a, b) = foo();’ Because that would be nice
May 12
On Tuesday, 13 May 2025 at 00:01:41 UTC, jmh530 wrote:In your rationale, you provide an example of how it works currently. You might show how it works with the DIP as well as a contrast.Thanks, that's a great idea.Am I right that any function that returns a tuple can use it like ‘auto (a, b) = foo();’ Because that would be niceYup, that's right.
May 12
On Tuesday, 13 May 2025 at 03:23:14 UTC, Meta wrote:On Tuesday, 13 May 2025 at 00:01:41 UTC, jmh530 wrote:For the record, Meta added an example with unpacking syntax for comparison: https://github.com/MetaLang/DIPs/blob/tuple-unpacking-dip/DIPs/DIP1052.md#rationaleIn your rationale, you provide an example of how it works currently. You might show how it works with the DIP as well as a contrast.Thanks, that's a great idea.
Jun 02
On Monday, 2 June 2025 at 12:12:49 UTC, Nick Treleaven wrote:On Tuesday, 13 May 2025 at 03:23:14 UTC, Meta wrote:Yeah, I had seen that. Nice improvement to the DIP.On Tuesday, 13 May 2025 at 00:01:41 UTC, jmh530 wrote:For the record, Meta added an example with unpacking syntax for comparison: https://github.com/MetaLang/DIPs/blob/tuple-unpacking-dip/DIPs/DIP1052.md#rationaleIn your rationale, you provide an example of how it works currently. You might show how it works with the DIP as well as a contrast.Thanks, that's a great idea.
Jun 02
On Monday, 12 May 2025 at 23:01:54 UTC, Meta wrote:The DIP: https://github.com/MetaLang/DIPs/blob/tuple-unpacking-dip/DIPs/DIP1052.mdAwesome DIP! To not have a built-in tuples in the lang is a shame! Just to clarify, will the static arrays gonna work? ```d (int a, float[3] b, string c) = tuple(1, 0.1, 0.2, 0.3, "2"); ```
May 13
On Tuesday, 13 May 2025 at 07:25:06 UTC, Sergey wrote:On Monday, 12 May 2025 at 23:01:54 UTC, Meta wrote:I'm pretty sure that works, except it should be [0.1, 0.2, 0.3].The DIP: https://github.com/MetaLang/DIPs/blob/tuple-unpacking-dip/DIPs/DIP1052.mdAwesome DIP! To not have a built-in tuples in the lang is a shame! Just to clarify, will the static arrays gonna work? ```d (int a, float[3] b, string c) = tuple(1, 0.1, 0.2, 0.3, "2"); ```
May 13
On 5/13/25 22:19, Meta wrote:On Tuesday, 13 May 2025 at 07:25:06 UTC, Sergey wrote:Has to be `[0.1, 0.2, 0.3].staticArray` actually, as there is no reverse type inference on IFTI. In the future perhaps constructs like `(int a, float[3] b..., string c) = tuple(1, 0.1, 0.2, 0.3, "2");` can be added, but this is not part of this DIP.On Monday, 12 May 2025 at 23:01:54 UTC, Meta wrote:I'm pretty sure that works, except it should be [0.1, 0.2, 0.3].The DIP: https://github.com/MetaLang/DIPs/blob/tuple-unpacking-dip/DIPs/ DIP1052.mdAwesome DIP! To not have a built-in tuples in the lang is a shame! Just to clarify, will the static arrays gonna work? ```d (int a, float[3] b, string c) = tuple(1, 0.1, 0.2, 0.3, "2"); ```
May 14
On Wednesday, 14 May 2025 at 17:00:02 UTC, Timon Gehr wrote:On 5/13/25 22:19, Meta wrote:Either of these seem to work with the unpacking branch: ```d (int a, float[3] b, string c) = tuple(1, [0.1F, 0.2F, 0.3F], "2"); (int a, double[3] b, string c) = tuple(1, [0.1, 0.2, 0.3], "2"); ```On Tuesday, 13 May 2025 at 07:25:06 UTC, Sergey wrote:Has to be `[0.1, 0.2, 0.3].staticArray` actually, as there is no reverse type inference on IFTI.Just to clarify, will the static arrays gonna work? ```d (int a, float[3] b, string c) = tuple(1, 0.1, 0.2, 0.3, "2"); ```I'm pretty sure that works, except it should be [0.1, 0.2, 0.3].
May 15
On 5/15/25 17:32, Nick Treleaven wrote:On Wednesday, 14 May 2025 at 17:00:02 UTC, Timon Gehr wrote:You are correct. I did not take into account that this works: ```d void main(){ int[] x=[1,2,3]; int[3] y=x; } ``` (I would actually prefer if this did not work.) It is not a great way to do it: ```d import std.typecons; void main() nogc{ (int a, float[3] b, string c) = tuple(1, [0.1F, 0.2F, 0.3F], "2"); // compile error } ``` ```d import std.typecons; void main(){ (int a, float[3] b, string c) = tuple(1, [0.1F, 0.2F, 0.3F, 0.4F], "2"); // runtime error } ``` Compare to: ```d import std.typecons, std.array; void main() nogc{ (int a, float[3] b, string c) = tuple(1, [0.1F, 0.2F, 0.3F].staticArray, "2"); // ok } ``` ```d import std.typecons, std.array; void main() nogc{ (int a, float[3] b, string c) = tuple(1, [0.1F, 0.2F, 0.3F, 0.4F].staticArray, "2"); // compile error } ```On 5/13/25 22:19, Meta wrote:Either of these seem to work with the unpacking branch: ```d (int a, float[3] b, string c) = tuple(1, [0.1F, 0.2F, 0.3F], "2"); (int a, double[3] b, string c) = tuple(1, [0.1, 0.2, 0.3], "2"); ```On Tuesday, 13 May 2025 at 07:25:06 UTC, Sergey wrote:Has to be `[0.1, 0.2, 0.3].staticArray` actually, as there is no reverse type inference on IFTI.Just to clarify, will the static arrays gonna work? ```d (int a, float[3] b, string c) = tuple(1, 0.1, 0.2, 0.3, "2"); ```I'm pretty sure that works, except it should be [0.1, 0.2, 0.3].
May 15
On Friday, 16 May 2025 at 06:08:41 UTC, Timon Gehr wrote:It is not a great way to do it: ```d import std.typecons; void main() nogc{ (int a, float[3] b, string c) = tuple(1, [0.1F, 0.2F, 0.3F], "2"); // compile error } ```The next logical step after this DIP is to enable initialization of a tuple with a struct literal: ```d (int a, float[3] b, string c) = { 1, [0.1F, 0.2F, 0.3F], "2" }; ```
May 20
On Tuesday, 20 May 2025 at 07:09:55 UTC, Ogion wrote:The next logical step after this DIP is to enable initialization of a tuple with a struct literal: ```d (int a, float[3] b, string c) = { 1, [0.1F, 0.2F, 0.3F], "2" }; ```Firstly, from the left-hand side, that is not tuple initialization. It is unpacking into declarations. Maybe you meant to have an identifier before the `=` token? Secondly, for tuple initialization from a literal, the right hand-side IMO would naturally be a *tuple literal*. Mentioned in (but not proposed by) the DIP: ```d auto t = (1, 2); // tuple literal ``` Also conceptually a tuple is not a struct. Unpacking a struct's fields implicitly is not supported by this DIP (and I don't think it should be as it complicates/limits future options).
Jun 02
On Monday, 12 May 2025 at 23:01:54 UTC, Meta wrote:[snip] The DIP: https://github.com/MetaLang/DIPs/blob/tuple-unpacking-dip/DIPs/DIP1052.mdTypo in one of the headers for the "Grammar Changes" section: "Proposal 5 (Unpacking function arguments)"
May 14
On Wednesday, 14 May 2025 at 17:45:12 UTC, jmh530 wrote:On Monday, 12 May 2025 at 23:01:54 UTC, Meta wrote:Thanks, PR: https://github.com/MetaLang/DIPs/pull/17[snip] The DIP: https://github.com/MetaLang/DIPs/blob/tuple-unpacking-dip/DIPs/DIP1052.mdTypo in one of the headers for the "Grammar Changes" section: "Proposal 5 (Unpacking function arguments)"
May 15
On Monday, 12 May 2025 at 23:01:54 UTC, Meta wrote:[snip] The DIP: https://github.com/MetaLang/DIPs/blob/tuple-unpacking-dip/DIPs/DIP1052.mdIf D adds built-in tuples in the future, would `.tupleof` be part of the language, or remain a library function? I ask because (in the limitations section) it says you can use that with static arrays or aggregates. I guess I'm wondering if it would be possible to check if `.tupleof` works for a given type and then implicitly call it if someone can be assumed to wanting an unpacked version of these types.
May 14
On Wednesday, 14 May 2025 at 18:09:11 UTC, jmh530 wrote:On Monday, 12 May 2025 at 23:01:54 UTC, Meta wrote:Funny you should mention that. I suggested the exact same thing to Timon, but what you are asking for is more complicated than it appears. I don't think .tupleof will be going anywhere, regardless of what happens with built-in tuples.[snip] The DIP: https://github.com/MetaLang/DIPs/blob/tuple-unpacking-dip/DIPs/DIP1052.mdIf D adds built-in tuples in the future, would `.tupleof` be part of the language, or remain a library function? I ask because (in the limitations section) it says you can use that with static arrays or aggregates. I guess I'm wondering if it would be possible to check if `.tupleof` works for a given type and then implicitly call it if someone can be assumed to wanting an unpacked version of these types.
May 14
On 5/14/25 20:09, jmh530 wrote:On Monday, 12 May 2025 at 23:01:54 UTC, Meta wrote:`.tupleof` in general is a low-level primitive that gives you a built-in auto-expanding sequence of all fields, including private ones. I don't think it is a good idea to call it implicitly for all types. For static arrays I think it would be defensible. In general, in the future we may want to e.g. add something like `opUnpack`. However, note that it is possible to instead create a member function that returns a tuple supported by unpacking, so this is just a minor convenience (assuming the most obvious design). One issue is unpacking by reference. In principle it should be possible to do that too, but DMD will not currently allow it due to this arbitrary limitation/bug: https://github.com/dlang/dmd/issues/21296[snip] The DIP: https://github.com/MetaLang/DIPs/blob/tuple-unpacking-dip/DIPs/DIP1052.mdIf D adds built-in tuples in the future, would `.tupleof` be part of the language, or remain a library function? I ask because (in the limitations section) it says you can use that with static arrays or aggregates. I guess I'm wondering if it would be possible to check if `.tupleof` works for a given type and then implicitly call it if someone can be assumed to wanting an unpacked version of these types.
May 14
On Thursday, 15 May 2025 at 02:17:15 UTC, Timon Gehr wrote:[snip] `.tupleof` in general is a low-level primitive that gives you a built-in auto-expanding sequence of all fields, including private ones. I don't think it is a good idea to call it implicitly for all types. For static arrays I think it would be defensible. In general, in the future we may want to e.g. add something like `opUnpack`. However, note that it is possible to instead create a member function that returns a tuple supported by unpacking, so this is just a minor convenience (assuming the most obvious design). [snip]In the back of my head I recall people complaining about some built-in features (I think related to dynamic or associated arrays) have some special behavior that we can't take advantage of in user-defined types. But probably worthwhile to add this DIP first and then think about `opUnpack` in the future.
May 15
On Monday, 12 May 2025 at 23:01:54 UTC, Meta wrote:Thanks to Timon and Nick Trealeven for doing the bulk of the implementation and conceptual work on this proposal.The hard work was all Timon's ;-)
May 15
On Monday, 12 May 2025 at 23:01:54 UTC, Meta wrote:This DIP proposes built-in tuple unpacking syntax for D. A sample of the proposed syntax: ```d import std.typecons : tuple; (int a, string b) = tuple(1, "2"); assert(a == 1); assert(b == "2"); auto (a, b) = tuple(1, "2"); static assert(is(typeof(a) == int)); static assert(is(typeof(b) == string)); auto (a, immutable b, c) = tuple(1, "2", 3.0); static assert(is(typeof(a) == int)); static assert(is(typeof(b) == immutable string)); static assert(is(typeof(c) == double)); ``` The DIP is based on Timon Gehr's old DIP for tuple syntax in D (https://github.com/tgehr/DIPs/blob/tuple-syntax/DIPs/DIP1xxx-tg.md), but is solely limited to support for unpacking; **it is not a full tuple-syntax DIP**. If the reception and general sentiment for this DIP are positive, further enhancements to add built-in tuple support to D may be proposed in the future. Thanks to Timon and Nick Trealeven for doing the bulk of the implementation and conceptual work on this proposal. I mainly just kickstarted things and am facilitating the DIP process. The DIP: https://github.com/MetaLang/DIPs/blob/tuple-unpacking-dip/DIPs/DIP1052.mdLet's say you have ``` auto (a, b) = tuple(1, "2"); ``` and decide to change the "2" to 2, so you now have ``` auto (a, b) = tuple(1, 2); ``` And then you're, like well why do I need `auto` here, I know the types. So then you write ``` (int a, int b) = tuple(1, 2); ``` Ok. That's fine. But then I would wonder why this DIP doesn't allow the following syntax: ``` int (a, b) = tuple(1, 2); ``` Why would someone want this? You might say, why would someone want a tuple with all the types the same? Why not just use a static (or dynamic) array instead of a tuple? Well, if they started with a tuple, then they may not want to go back and change it. Less re-factoring. But if the unpacking syntax can work with tuples, then why not also have it work for arrays?
May 20
On 5/20/25 14:27, jmh530 wrote:Ok. That's fine. But then I would wonder why this DIP doesn't allow the following syntax: ``` int (a, b) = tuple(1, 2); ```a) With C-style conventions, `int (a, b)` would say: we declare that the expression `(a, b)` has type `int`, which is not what we are looking for. b) Grammar ambiguity. `T (a, b) = tuple(1, 2)` could just as well be read as `T(a,b).opAssign(tuple(1,2))`.
May 20
On Tuesday, 20 May 2025 at 19:29:34 UTC, Timon Gehr wrote:On 5/20/25 14:27, jmh530 wrote:On a), the DMD compiler won't let you write `int (a, b);` It looks like what it is trying to do is to construct something (suggesting the issue is similar to what you describe in b)). One potential solution would be that `T(a, b) = tuple(1, 2)` gets lowered to `T(a,b).opAssign(tuple(1,2))`, but `T (a, b) = tuple(1, 2)` gets lowered to `T(a,b).opUnpack(tuple(1,2))`. Potentially breaks code. If you believe a) is an issue, does that make you cautious at all about allowing `auto (a, b)`? Now that I've thought about it, I wonder if people might potentially find that confusing.Ok. That's fine. But then I would wonder why this DIP doesn't allow the following syntax: ``` int (a, b) = tuple(1, 2); ```a) With C-style conventions, `int (a, b)` would say: we declare that the expression `(a, b)` has type `int`, which is not what we are looking for. b) Grammar ambiguity. `T (a, b) = tuple(1, 2)` could just as well be read as `T(a,b).opAssign(tuple(1,2))`.
May 21
On 5/21/25 18:34, jmh530 wrote:On Tuesday, 20 May 2025 at 19:29:34 UTC, Timon Gehr wrote:This is not what it would lower to, a method call cannot declare free variables in the receiver. If you want to accept an explicit type, you have to do it in two steps: ```d Tuple!(int, int) t = foo(); auto (a, b) = t; ``` It does not really make sense to name a type for `(a, b)`, at least not without support for tuple type syntax.On 5/20/25 14:27, jmh530 wrote:On a), the DMD compiler won't let you write `int (a, b);` It looks like what it is trying to do is to construct something (suggesting the issue is similar to what you describe in b)). One potential solution would be that `T(a, b) = tuple(1, 2)` gets lowered to `T(a,b).opAssign(tuple(1,2))`, but `T (a, b) = tuple(1, 2)` gets lowered to `T(a,b).opUnpack(tuple(1,2))`. Potentially breaks code. ...Ok. That's fine. But then I would wonder why this DIP doesn't allow the following syntax: ``` int (a, b) = tuple(1, 2); ```a) With C-style conventions, `int (a, b)` would say: we declare that the expression `(a, b)` has type `int`, which is not what we are looking for. b) Grammar ambiguity. `T (a, b) = tuple(1, 2)` could just as well be read as `T(a,b).opAssign(tuple(1,2))`.If you believe a) is an issue, does that make you cautious at all about allowing `auto (a, b)`?I don't see how that would be an issue for allowing `auto (a, b) =`. `auto` is not a placeholder for a type, it is a storage class, like `scope` or `immutable`.Now that I've thought about it, I wonder if people might potentially find that confusing.`(int, int) (a, b) = (1, 2);` does not work. It's pretty much the same thing and I think it makes sense.
Jun 01
On Monday, 12 May 2025 at 23:01:54 UTC, Meta wrote:This DIP proposes built-in tuple unpacking syntax for D. A sample of the proposed syntax: ```d import std.typecons : tuple; [...]Why not a full tuple DIP?
Jun 02
On Monday, 2 June 2025 at 19:48:07 UTC, Atila Neves wrote:On Monday, 12 May 2025 at 23:01:54 UTC, Meta wrote:I discussed it with Timon and Nick, but we decided to limit the scope to unpacking, because the other stuff can be added down the line, and doing it this way keeps the DIP much simpler.This DIP proposes built-in tuple unpacking syntax for D. A sample of the proposed syntax: ```d import std.typecons : tuple; [...]Why not a full tuple DIP?
Jun 02
On 6/2/25 21:48, Atila Neves wrote:On Monday, 12 May 2025 at 23:01:54 UTC, Meta wrote:Unpacking is the biggest tuple-related omission in D's current feature set, and we can make that work now by pulling the already existing implementation. There is an incomplete proof of concept implementation that currently lowers to `std.typecons.Tuple` here: https://github.com/tgehr/dmd/tree/tuple-syntax The goal is to make that either a built-in type with all bells and whistles or at the very least lower to a new struct in druntime instead. Some more work is required for design and implementation of the full tuple DIP, for example: - `opArgs`? (i.e., calling an n-ary function with a single n-tuple of its arguments). I have a design that I like where `void foo(int x,)` declares `foo` as unpacking a `1`-tuple argument analogous to how `(int x,) = t;` would unpack such a `1`-tuple, but this is a) a breaking change and b) probably somewhat controversial. It's also only partially implemented at the moment. - static indexing and slicing operators for structs. - it seems unpacking assignment is not so easy to implement in a clean way, particularly if tuple expressions are lowered early in semantic analysis (c.f. https://github.com/tgehr/dmd/pull/12 ) - `()` should be both a type and an expression and should be supported as an alias parameter as such - reverse type inference like `(bool function(int), string delegate(bool)) t = (x=>!!x, x=>text(x));` is not implemented at all. It's mostly a matter of me currently not being able to put in the time and energy required to pull off a full tuple DIP, but any help is of course appreciated. Meta and Nick have been stepping up to help get unpacking over the finish line.This DIP proposes built-in tuple unpacking syntax for D. A sample of the proposed syntax: ```d import std.typecons : tuple; [...]Why not a full tuple DIP?
Jun 05
On Thursday, 5 June 2025 at 18:10:30 UTC, Timon Gehr wrote:On 6/2/25 21:48, Atila Neves wrote:I just hope you relevant people can get some good discussion on this at dconf, and make some affirmative decision to implement it in 2025... (perhaps even with some breaking changes along the way). Good luck with a swift and good decision.[...]Unpacking is the biggest tuple-related omission in D's current feature set, and we can make that work now by pulling the already existing implementation. [...]
Jun 05
On Thursday, 5 June 2025 at 18:10:30 UTC, Timon Gehr wrote:On 6/2/25 21:48, Atila Neves wrote:Ok, thanks.[...]Unpacking is the biggest tuple-related omission in D's current feature set, and we can make that work now by pulling the already existing implementation. [...]
Jun 12