DIP 88: Simple form of named parameters

arturg via Digitalmars-d digitalmars-d at puremagic.com
Mon Jan 25 06:35:09 PST 2016


On Monday, 25 January 2016 at 13:40:18 UTC, HaraldZealot wrote:
> On Saturday, 23 January 2016 at 14:19:03 UTC, Jacob Carlborg 
> wrote:
>> This is mostly to prevent ugly hacks like Flag [1].
>>
>> http://wiki.dlang.org/DIP88
>>
>> [1] https://dlang.org/phobos/std_typecons.html#.Flag
>
> Why not simply allow programmer to declare auto variable at 
> function call side like in `foreach`?
>
> E.g.
>
> ```d
> void foo(int width, int height){...} //function definition
>
> foo(width = 2, height = 3); // function call
> ```

the equal sign cant be used because D behaves like this

int width, height;

foo(width = 5, height = 10); // 5
                              // 10
width.writeln;  // 5
height.writeln; // 10

void foo(int width, int height)
{
     width.writeln;
     height.writeln;
}

and in python

def foo(width, height):
     print(width)
     print(height)

width = 0
height = 0
foo(width = 5, height = 10) # 5
                             # 10
print(width)  # 0
print(height) # 0



More information about the Digitalmars-d mailing list