proposed syntax for tuple: t{} and TypeTuple: T{} (cf precedent of q{...})
Nick Treleaven via Digitalmars-d
digitalmars-d at puremagic.com
Fri Apr 8 04:00:05 PDT 2016
On Tuesday, 5 April 2016 at 14:00:46 UTC, ag0aep6g wrote:
> I'm not sure if the new syntax is worth adding, though.
> `T{...}` (or `T[...]`) saves just one character over `T!(...)`.
> The latter can be done without touching the language. For the
> value tuple, one can do `alias t = std.typecons.tuple;` which
> gives you `t(...)`. That's just as short as `t{...}`. But maybe
> std.typecons.tuple is lacking somehow. A more proper `t(...)`
> could be implemented when functions could return tuples, which
> would also be desirable if we had `t{...}` syntax. So
> implementing `T!(...)` and `t(...)` in D seems like the way to
> go to me. And maybe allow functions to return tuples.
Functions can return std.typecons.tuple. All that is needed IMO
is unpacking syntax:
auto (int x, y) = someTuple;
Rather than adding this specific feature, we could allow
declarations as out arguments to functions like C# does. Or
better, have Rust-like pattern matching macros:
macro unpack(Declaration...);
$unpack(int x, auto y) = someTuple;
More information about the Digitalmars-d
mailing list