D with experimental features like tuple unpacking
Dmitry Olshansky
dmitry.olsh at gmail.com
Fri Mar 22 04:14:45 PDT 2013
22-Mar-2013 14:58, bearophile пишет:
>
> Jacob Carlborg:
>
>>> auto (lof, loa) = heap.front;
>>
>> How is front suddenly returning two elements?
>
> It is not returning two elements. In D you can't return two elements. It
> is returning a 2-Tuple. You see the 2-tuples are built by the map() and
> then used to create a heap:
>
> auto heap = sf.map!(((c, f)) => tuple(f, ...)).array.heapify!q{...};
>
>
> And this proposed syntax performs pattern matching on that 2-tuple,
> unpacking it into two variables (Hara has implemented this already):
>
> 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.
Thus I'd go for struct destructuring syntax like (god forgive) JS6.
I even had proposal to about same effect, but it was ignored. Among
other things it replace .tupleof with more general destructuring facility.
--
Dmitry Olshansky
More information about the Digitalmars-d
mailing list