Tuple literal syntax
Tomek Sowiński
just at ask.me
Thu Oct 7 13:27:22 PDT 2010
Andrei Alexandrescu napisał:
> On the client side the syntax is very light. The definition of the
> function would need to specify the type name:
>
> Tuple!(int, "foo", string, "bar") fun(int) {
> ...
> }
Blue sky idea -- anonymous structs:
struct { int foo; string bar; } fun(int) {
...
}
They already exist but are allowed only as members of other structs/unions. Then again,
it's still a language trip-up, like we don't have enough of those already.
> I think much of the list of grievances against tuple limitations stems
> from a feeling that doing tuples without special syntax is "cheating".
> For my money, library tuples are eminently usable, and once we fix a
> couple of compiler bugs, they will be as good as (if not simpler,
> richer, and clearer than) a built-in facility.
Amen.
> I do want to introduce
> syntax for expansion a la
>
> auto (a, b) = foo(42);
>
> because that's a common need that's not satisfiable via a library.
Nice, but I can live without that.
> But
> then I want to define the syntax in a general way so it works not only
> with tuples, but also with arrays and types that implement opIndex.
There's a tangent issue with std.typecons.Tuple:
int[2] ints;
Tuple!(int, int) t = ints;
Minor, but should work.
--
Tomek
More information about the Digitalmars-d
mailing list