Named Arguments Status Update

Walter Bright newshound2 at digitalmars.com
Tue Jan 9 00:53:45 UTC 2024


On 1/5/2024 1:48 AM, Dennis wrote:
> ## Forwarding?
> 
> (This did not come up in the implementation, but was pointed out by Timon Gehr 
> on Discord.)
> 
> Is there a way to forward named arguments? Consider:
> 
> ```D
> import std.stdio;
> 
> int f(int x, int y);
> 
> auto logAndCall(alias f, T...)(T args)
> {
>      writeln(args);
>      return f(args);
> }
> 
> logAndCall!f(y: 1, x: 0);
> ```
> 
> Are the names propagated to the `T args` parameter? If so, that wouldn't be 
> hygienic:
> Imagine an argument named `writeln` - it would hijack the function call!

I would say no, they do not propagate to the parameter. I expect it would 
confuse the hell out of people.


> Perhaps we could allow access to names some other way, like `args.x`. But still, 
> if we had another parameter `(T args, string file)` then the called function 
> could not have a parameter named `file`.

I'd go a step further. Disallow named arguments being passed as a variadic 
argument list. We can always turn it on later if some compelling reason turns up.


More information about the Digitalmars-d mailing list