2 days ago
On 5/13/25 22:19, Meta wrote:
> On Tuesday, 13 May 2025 at 07:25:06 UTC, Sergey wrote:
>> 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.md
>>
>> Awesome 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");
>> ```
> 
> I'm pretty sure that works, except it should be [0.1, 0.2, 0.3].

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.
2 days ago

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.md

Typo in one of the headers for the "Grammar Changes" section:
"Proposal 5 (Unpacking function arguments)"

2 days ago

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.md

If 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.

2 days ago

On Wednesday, 14 May 2025 at 18:09:11 UTC, jmh530 wrote:

>

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.md

If 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.

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.

2 days ago
On 5/14/25 20:09, jmh530 wrote:
> 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.md
> 
> If 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.

`.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
1 day ago

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.

1 day ago

On Wednesday, 14 May 2025 at 17:45:12 UTC, jmh530 wrote:

>

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.md

Typo in one of the headers for the "Grammar Changes" section:
"Proposal 5 (Unpacking function arguments)"

Thanks, PR:
https://github.com/MetaLang/DIPs/pull/17

1 day ago

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 ;-)

1 day ago

On Wednesday, 14 May 2025 at 17:00:02 UTC, Timon Gehr wrote:

>

On 5/13/25 22:19, Meta wrote:

>

On Tuesday, 13 May 2025 at 07:25:06 UTC, Sergey wrote:

>

Just to clarify, will the static arrays gonna work?

(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].

Has to be [0.1, 0.2, 0.3].staticArray actually, as there is no reverse type inference on IFTI.

Either of these seem to work with the unpacking branch:

(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");
1 day ago
On 5/15/25 17:32, Nick Treleaven wrote:
> On Wednesday, 14 May 2025 at 17:00:02 UTC, Timon Gehr wrote:
>> On 5/13/25 22:19, Meta wrote:
>>> On Tuesday, 13 May 2025 at 07:25:06 UTC, Sergey wrote:
>>>> 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].
>>
>> Has to be `[0.1, 0.2, 0.3].staticArray` actually, as there is no reverse type inference on IFTI.
> 
> 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");
> ```
> 

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
}
```
1 2
Next ›   Last »