DIP19: Remove comma operator from D and provision better syntactic support for tuples

Timon Gehr timon.gehr at gmx.ch
Sun Sep 23 15:42:29 PDT 2012


On 09/23/2012 10:40 PM, Andrei Alexandrescu wrote:
> I discussed this with Walter, and we concluded that we could deprecate
> the comma operator if it helps tuples. So I started with this:
>
> http://www.prowiki.org/wiki4d/wiki.cgi?LanguageDevel/DIPs/DIP19
>
> Unfortunately, I started much cockier than I ended.  The analysis in
> there fails to construct a case even half strong that deprecating the
> comma operator could significantly help tuples.

That is because it does not base the discussion on the right
limitations of built-in tuples:

auto (a,b) = (1,"3");
(auto a, string b) = (1, "3");

BTW: the following works

Tuple!(int, string) t2 = t1[0 .. 2];

because of this:

=> (alias this)

Tuple!(int, string) t2; t2._fields = t1[0 .. 2];

=> (tuple assignment)

Tuple!(int, string) t2; t2._fields[0]=t1[0]; t2._fields[1]=t1[1];

> Well it essentially
> concludes that tuples are mostly fine as they are, and attempts to
> embellish them syntactically are marred with unexpected problems.
> Nevertheless, I sure have missed aspects all over, so contributions are
> appreciated.
>

- We already use the name 'tuple'. I'd suggest renaming that to
   'sequence' or similar. template Seq(T...){ alias T Seq; }

- The empty tuple can well be (), just like 'Seq!()' works without
   issues (it is an expression that is also a type). What is wrong with
   it?

- How do we expand a sequence into a tuple?
   => (Seq!(1,2,3),)

- What is the calling convention used for passing built-in tuples to
   and from functions?

- As tuples are built-in, expansion can be shorter than '.expand'.
   foo(1, tup..., 3); ?

- Template tuple parameters? This would work, but...
   template Tuple((T...,)){ alias (T,) Tuple; }

   void bar(T,(U...,),V...)(T delegate(U) dg, V args){ ... }
   void foo(T,(U...,),(V...,))(T delegate(U) dg, V args){
      bar!(T,Tuple!U,V)(dg, args);
   } // U and V can be passed separately

- Named tuple fields?

   (int x, int y) tuple = (1,2);

   swap(tuple.x, tuple.y);



More information about the Digitalmars-d mailing list