Struct initializers as expressions

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Dec 4 03:25:12 PST 2015


On Friday, 4 December 2015 at 10:42:46 UTC, Marc Schütz wrote:
;
>
> Then we can add some syntax sugar to leave out the braces, too:
>
>     void bar(int a, T t)
>     bar(42, a: "bla", b: "xyz");
>
> This effectively gives us strongly typed named arguments, 
> without making the names part of the function signature, which 
> Walter objected to the last time something like this was 
> proposed.

I like the idea of field names in a struct literal, but I would 
prefer to keep the parens. And no braces! The syntax for literals 
is already recommended over the C-style initializers, so IMO the 
same ought to hold for named initializers. I agree with dropping 
the struct name, though.

bar(42, (a: "bla", b: "xyz"))

I realized that if named arguments are not supported, then 
dropping the parens should still indicate that you're dealing 
with a struct, but the clear delineation is much more obvious. It 
also holds the door open for Walter to change his mind on named 
arguments.



More information about the Digitalmars-d-learn mailing list