Should we deprecate comma?
bearophile
bearophileHUGS at lycos.com
Mon Mar 24 10:51:14 PDT 2014
Dicebot:
> I understand but this is something that can be pretty hard to
> fit into D semantics/grammar and I am not sold that it is worth
> the push on its own.
I'd like a good tuple syntax in D.
> What is the difference with this then?
>
> void foo(int a, int b, int c)
> {
> // ...
> }
>
> auto t = tuple(10, 20, 30);
> foo(t.expand);
The difference is that your experience with tuples will be less
good. One difference can be seen here. Given an array of tuples
(here I am using a shorter syntax):
auto arr = [@{1, 2}, @(3, 4)]
You can't do this:
void foo(int a, int b, int c) {...}
auto result = arr.map!foo;
And you need:
auto result = arr.map!(t => foo(t.expand));
Or:
auto result = arr.map!(t => foo(t[]));
While you can do this:
void foo(in @(int a, int b, int c}) {...}
auto result = arr.map!foo;
The point of having a tuple syntax is not to expand the set of
programs you can write with C language. It's of having a handy
syntax to perform certain very common operations with more than
one type.
I also suggest you to take a look at the DIP.
Bye,
bearophile
More information about the Digitalmars-d
mailing list