Flag proposal

Michel Fortin michel.fortin at michelf.com
Tue Jun 14 05:34:53 PDT 2011


On 2011-06-13 21:36:01 -0400, so <so at so.so> said:

> IMO named arguments in D at least should do:
> 
> - Reordering (since we got default parameters, even better)
> 
> - It is enabled only if we have access to the function declaration.
> 
> - In a function call we either use named arguments for all the 
> non-default  arguments or call it with the usual syntax. No hybrid 
> stuff, no confusion.
> 
>    fun(int a, int b, int c=3)
> 
>    fun(1, 2, 3) // fine - current
>    fun(1, 2) // fine - current
> 
>    fun(a:1, b:3, c:5) // fine
>    fun(a:1, b:3) // fine
>    fun(b:1, c:3, a:5) // fine
>    fun(b:1, a:3) // fine
>    fun(b:1) // error
>    fun(c:1) // error
>    fun(2, b:1) // error
>    fun(2, c:1) // error
>    fun(2, c:2, 3) // error

There's much more to named arguments as it first appears. Have you 
thought about:

1. variadic arguments?
2. named template arguments?
3. template variadic arguments (tuples) and how they expand as function 
parameters?

Also, with reordering, if you have two overloaded functions of this form:

	void fun(int a, string b) {}
	void fun(string b, int a) {}

which one does this calls:

	fun(a: 1, b: "hello");

? Does the call become ambiguous when using named arguments? It 
wouldn't be ambiguous if reordering wasn't allowed. What does C# does 
with this?


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d mailing list