D with experimental features like tuple unpacking

bearophile bearophileHUGS at lycos.com
Fri Mar 22 04:25:54 PDT 2013


Dmitry Olshansky:

>> auto (lof, loa) = ...;
>>
>> In Haskell, Scala, Python, F#, etc, the semantics and syntax 
>> are similar.
>>
>
> I'd hate any solution that distances ordinary structs, library 
> tuples and fixed-sized arrays. If anything these should be 
> trivially substitutable where makes sense.

In Bugzilla I suggested that syntax for arrays too, I'd like that:

int[2] data = [10, 20];
auto (a, b) = data;


Regarding tuples and structs, Tuples are implemented as structs, 
so forbidding struct unpacking is probably more work than not 
doing it. On the other hand structs and tuples are not exactly 
the same thing, despite one is implemented with the other.


> I even had proposal to about same effect, but it was ignored. 
> Among other things it replace .tupleof with more general 
> destructuring facility.

I don't want to use ".tupleof" to unpack a Tuple. Because it's a 
very commonly done operation, so it needs a short syntax.

---------------------------

John Colvin:

> tldr: If we're going to have tuple unpacking, we need some way 
> of controlling it.

I agree, that's why in my proposed code I have added parentheses:

foreach ((c, ref e); loa)

foreach ((c, e); s.dup.sort().release.group.encode)

Bye,
bearophile


More information about the Digitalmars-d mailing list