proposed syntax for tuple: t{} and TypeTuple: T{} (cf precedent of q{...})

ag0aep6g via Digitalmars-d digitalmars-d at puremagic.com
Tue Apr 5 07:00:46 PDT 2016


On 05.04.2016 07:45, Timothee Cour via Digitalmars-d wrote:
> How about the following syntax instead:
>
> ----
> {} // delegate (existing syntax)
> q{...} // string literal (existing syntax)
> t{...} // tuple(a,b) (proposed syntax)
> T{...} // TypeTuple!(a,b) (proposed syntax)
> ----

In existing syntax, most {...} blocks can contain semicolon separated 
declarations. Your proposed constructs would be comma separated lists. 
I'd vote for other delimiters because of that. Static struct 
initializers are the exception in existing syntax, but they stick out, 
and they're not used often.

Parentheses are not an option because of arbitrary identifiers in 
function calls and such, and making `t`/`T` keywords for this purpose 
doesn't seem wise. That leaves square brackets. `t[...]` doesn't clash 
with anything, as far as I see. And it makes a good fit for the feature, 
in my opinion. So I'd prefer `t[...]` over `t{...}`.

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.


More information about the Digitalmars-d mailing list