DIP19: Remove comma operator from D and provision better syntactic support for tuples
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sun Sep 23 15:57:45 PDT 2012
On 9/23/12 6:42 PM, Timon Gehr wrote:
> 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");
I meant to mention that but forgot. The interesting thing about this is
that, if we decide it's the main issue with today's tuples, we pull
Kenji's patch and close the case.
> 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];
Yah, I thought the writeup clarified that.
> - We already use the name 'tuple'. I'd suggest renaming that to
> 'sequence' or similar. template Seq(T...){ alias T Seq; }
Then what are the "old" tuples?
> - 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?
There's already intensive use of parens in D. I predict there's going to
be big trouble with "()" even assuming it's not technical ambiguous, for
example a lambda that returns an empty tuple would be "()() {...}" and
all that jazz.
> - How do we expand a sequence into a tuple?
> => (Seq!(1,2,3),)
I think we're discussing different things - the above seems to deal with
expression/alias tuples. DIP19 discusses strictly runtime value tuples.
> - What is the calling convention used for passing built-in tuples to
> and from functions?
I don't know. The current approach with .expand is nothing special - as
if the programmer wrote the expansion by hand.
> - As tuples are built-in, expansion can be shorter than '.expand'.
> foo(1, tup..., 3); ?
I find that sugar gratuitous.
> - 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);
I kinda got lost around all that.
Andrei
More information about the Digitalmars-d
mailing list