DIP32: Uniform tuple syntax

kenji hara k.hara.pg at gmail.com
Fri Mar 29 03:01:30 PDT 2013


2013/3/29 Dmitry Olshansky <dmitry.olsh at gmail.com>

> A few typos like:
> {c, $} = tup;   // Rewritten as: a = tup[0];
> where it should be //Rewritten as c = tup[0];
>

Thanks. Fixed.


> About swapping values by tuple assignment.
>
> Why not simply make this work:
> {x, y} = {y, x}
>
> By lowering
> {x, y}  = {y, x};
> to
> auto temp0 = y;
> auto temp1 = x;
> x = temp0;
> y = temp1;
>
> And let the compiler do value propagation to remove the extra temp0.
>

Because it already exists.

template Seq(T...) { alias Seq = T; }
void main()
{
    int x = 1, y = 2;
    Seq!(x, y) = Seq!(y, x);    // tuple assigmnent
    assert(x == 2);
    assert(y == 2);
}

Another note - is there any way to extend this notation to common structs
> other then .tupleof ? I think we may hopefully extended it later towards
> struct destructruing a-la EcmaScript 6, see
>
> http://wiki.ecmascript.org/**doku.php?id=harmony:**destructuring<http://wiki.ecmascript.org/doku.php?id=harmony:destructuring>


Hmm, interesting. I'll see it later.

Kenji Hara
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130329/9c35df33/attachment-0001.html>


More information about the Digitalmars-d mailing list