Worst ideas/features in programming languages?

Walter Bright newshound2 at digitalmars.com
Sat Jan 8 01:16:14 UTC 2022


On 1/4/2022 3:36 PM, Timon Gehr wrote:
> On 04.01.22 08:52, Walter Bright wrote:
>> On 1/3/2022 10:37 PM, Timon Gehr wrote:
>>> If `foo(int, int)` is defined to be literally the same as `foo(int[2])`, 
>>> there is no conversion. But anyway, I guess you'd also consider anything that 
>>> would make this work an "implicit conversion"?
>>>
>>> double foo(int x,string y);
>>>
>>> writeln([(1,"2"),(1,"3"),(3,"4")].map!foo);
>>
>> Currently, tuples can map right on to argument lists, there is no conversion. 
>> This works because a tuple in D isn't really a type at all. It's just a 
>> collection of expressions.
>> ...
> 
> But in the example above, those so-called "tuples" would expand right into the 
> array literal and cause an error due to incompatible types. This can't work if 
> `(1,"2")` etc. auto-expand. Furthermore, to put them into an array, they need to 
> have an address.

I know. It's a problem.


>>> If so, maybe one way to make _some_ progress on this is to have a DIP 
>>> specifically for destructuring, without adding any new types?
>>
>> I'm not sure what destructuring,
> 
> Currently working with tuples (including actual tuples that are actual 
> expressions, e.g., Phobos tuples) is inconvenient mostly (but not only) because 
> you can't easily expand them into multiple named variables.
> 
> ```d
> auto (col1, col2) = table.query!((ref row)=>tuple(row.column1,row.column2))(key);
> ```
> 
> Proposal 1 here:
> https://github.com/tgehr/DIPs/blob/tuple-syntax/DIPs/DIP1xxx-tg.md
> 
> Proof-of-concept implementation here:
> https://github.com/tgehr/dmd/commit/8ad53b0891d3353dd96711595c06326ac0195d1b
> https://github.com/tgehr/dmd/commit/a0f59f93ab3727c93585dc658444860926a4b2c6
> 
>> but yes, not adding new types.
> 
> That's what I thought, so the tuple DIP is based on lowering to structs.
> 
> What's the path forward to making this work?

I don't know. I'll have to look at your proposals.

> 
> ```d
> double foo(int x,string y);
> 
> writeln([(1,"2"),(1,"3"),(3,"4")].map!foo);
> ```
> 
> My suggestion was proposal 2 here:
> https://github.com/tgehr/DIPs/blob/tuple-syntax/DIPs/DIP1xxx-tg.md
> 
> Proof-of-concept implementation here:
> https://github.com/tgehr/dmd/commit/bdb40fa96c471a7ace84596511a27ba3e803214f
> https://github.com/tgehr/dmd/commit/dad942117d85683e6234ef312c6d59be82f0c3a2
> 
> Note that Phobos tuples are implemented using an `alias this` to a built-in 
> "tuple" of members:
> https://github.com/dlang/phobos/blob/master/std/typecons.d#L636-L655




More information about the Digitalmars-d mailing list