Tuple-icious

Walter Bright newshound2 at digitalmars.com
Sat Apr 27 01:58:08 UTC 2024


On 4/26/2024 4:30 PM, Timon Gehr wrote:
> On 4/26/24 22:23, Walter Bright wrote:
>> I would like to see "new C()" and "tuple(new C())" mean exactly the same 
>> thing. After all, with the builtin-tuples (not the struct library version) 
>> they are the same thing.
>>
> 
> Ok, then I will further pursue an implementation of `opArgs` I guess. It does 
> have a couple of drawbacks, but if this is your preference we can try to make it 
> work.

I also mean that given:
```
int mul(int x, int y);
```
then:
```
mul(1, 2);
```
should mean the same thing as:
```
mul(tuple(1, 2));
```

This currently works with the builtin tuples. The trouble is that:

```
struct Args { int a; int b };
Args args = { 1, 2 };
mul(args);
```

fundamentally does not work, because the binary function call API for arguments 
is not the same as the binary function call API for structs with the 
corresponding fields.

This has frustrated me for some time. Static arrays and structs are binary API 
compatible, and I've been careful not to break that in D's design. I.e. they are 
unified. I'd like to extend that unification to tuples-as-arguments.

I.e.:

```
struct <=> static array <=> tuple <=> argument list
```

should be binary interchangeable.

Note that I was very pleased to make the discovery that pointers to:

struct member functions <=> class member functions <=> nested functions

are all interchangeable delegates! This has been a big win for D.


More information about the Digitalmars-d mailing list