DIP32: Uniform tuple syntax
bearophile
bearophileHUGS at lycos.com
Fri Mar 29 06:29:18 PDT 2013
Simen Kjærås:
>> void foo(t2@{int a, string b}) {
>> // here a and b are tuple items and t2 is the whole tuple.
>> }
>> auto t1@{x, y} = {10, "hi"};
>> foo(t1);
>
> I suggest instead this syntax:
>
> auto {x, y} t1 = {10, "hi"};
>
> It's closer to regular D syntax.
But I'd like sometime to tie t1 to that {}, to help my eyes.
>> {c, $_} = tup;
>> {c, @} = tup;
>> {c, @_} = tup;
>> {c, $$} = tup;
>> ...
>> {c, {_}} = tup;
>> {c, $~} = tup;
>> ...
>> etc.
>
> ... has been introduced to match zero or more elements for
> pattern matching
> already. I see no reason not to use ... for this.
Telling the language that there there is exactly one item to
match on, that you don't care of, is important. The "..." syntax
can't tell apart the case for zero, one, or more items. So "..."
can't be enough here.
Bye,
bearophile
More information about the Digitalmars-d
mailing list