DIP 1020--Named Parameters--Community Review Round 2

rikki cattermole rikki at cattermole.co.nz
Thu Sep 12 07:09:53 UTC 2019

On 12/09/2019 11:01 AM, Walter Bright wrote:
> On 9/11/2019 12:18 AM, rikki cattermole wrote:
>> But I need to confirm with you before I do this, is this for the 
>> replacement of in place struct initialization syntax?
>> If so I want to solve that, but I need to ask you how you would want 
>> it done. Since it touches upon .init, it makes me a little concerned 
>> because of dragons.
> I'm planning to replace:
>    struct S { int a, b; }
>    S s = { 1, 2 };
> with:
>    S s = S(1, 2);
> D is almost there already, but is missing the named parameter feature to 
> go all the way.
> I'm looking at other ways as well to unify and thereby simplify D.

Okay so it is what I'm thinking.

I currently have three solutions to support in place struct 
initialization with DIP 1020.

I would like to know which direction you would like me to go.

1. Syntax magic
2. Generate a constructor (which bypasses restrictions)
3. Hope somebody else figures out how to do it, but state that it is 

I'm currently leaning towards 2 but it would mean researching what 
restrictions are in place, why they are in place and make sure I'm not 
breaking anything in the type system.

We would end up having two constructors generated, if the default 
constructor is not @disabled or if no constructors are defined. I'm not 
sure which restriction (or both).

struct Foo {
	int x, y;

	// generated
	this(@named int x = int.init,
		@named int y = int.init) {
		this.x = x;
		this.y = y;

	// generated
	this(int x, int y=int.init) {
		this.x = x;
		this.y = y;

More information about the Digitalmars-d mailing list