I presented my workaround
here and also suggested this around 2 years ago on Developers forum.
f(p1, , p3)
I sometimes wish this, but named parameters are much much better idea. The problem with above is that you will soon have "InputBox" symptom:
InputBox(txt,,,,,,,,,,,title)
About named parameters the problem with assignment can be fixed with literals:
Fun("Name" := Name, "Pos":=6 )since you cant assign to literal.
There are dozens of ways to do it, lets give examples on:
Declare:1. f(p1,p2="",Name:,Pos:=6)
2. f(p1,p2="","Name","Pos"=6)
3. f(p1,p2="") {
params Name, Pos=6 ;position is important.
}
Use1. f(1,2,Name:A_Script)
2. f(1,2,"Name"=A_Script)
3. Can use either 1 or 2
To me, the best looking are 3+1 or 1+1
Here are some examples on 1+1:
f(p1,p2="",Name:,Pos:=6){
if Name=
;some code here
}
f(1), f(1,2) ;as usual
f(1, Pos:6) ;valid, p2 will take default
f(Pos:6) ;invalid, p1 is mandatory
f(1, Name: x ? v:k, Pos:A_Index+1)
f(1, 2, Name, Pos) ;not using named params
f(1, 2, Pos) ;mistake, Name is defined on third position
f(1, 2, "My Name", 6) ;all literals
f(1, 2, "My Name", Pos:3) ;mixed, first named parameter by position, second by name.
f(1, 2, Pos:3, Name:"My Name", Pos:6) ;although it could be done so that last pos overrides first one, perhaps error is better idea.
name=Pos
value= My Name
f(1, %Name%:Value) ;dynamic
InputBox, param
fun = f
%f%(j, %Param%:Value) ;dynamic function with dynamic parameter
So, in short, function argument list consist of 2 parts, unnamed part that is determined by position and named part. Parts can not be mixed as constructs like the following are meaningless:
f(1,2,Name:55, 7) ; error , positional parameter after named