
|
If you were logged in you would be able to see more operations.
|
|
|
The following code demonstrates the problem. It is handy to be able to "apply" arguments to a function/closure, but these calls do not properly handle the presence of default arguments.
def xx = { a, b, c = "default" -> println "a $a b $b c $c"; };
xx(1, 2, 3);
xx([1, 2, 3]);
z = [1, 2, 3];
xx(z);
z = [1, 2];
xx(1, 2);
xx(z);
def yy (a, b, c = "default") { println "a $a b $b c $c"; };
yy(1, 2, 3);
yy([1, 2, 3]);
z = [1, 2, 3];
yy(z);
z = [1, 2];
yy(1, 2);
yy(z);
This would make the following ambiguous:
def zz (a, b = "default", c = "default") { println "a $a b $b c $c"; };
zz([1, 2, 3]);
There needs to be a way, as with Java varargs, to indicate when an array is "an array of arguments" and when it is "an argument that is an array".
The current, Java-like approach may not be the best. It would be nice to have an "apply" method on functions/closures that would explicitly take "an array of arguments", much like Scheme/JavaScript:
def zz (a, b = "default", c = "default") { println "a $a b $b c $c"; };
zz([1, 2, 3]); // "a [1, 2, 3] b default c default"
zz.apply([1,2,3]); // "a 1 b 2 c 3"
|
|
Description
|
The following code demonstrates the problem. It is handy to be able to "apply" arguments to a function/closure, but these calls do not properly handle the presence of default arguments.
def xx = { a, b, c = "default" -> println "a $a b $b c $c"; };
xx(1, 2, 3);
xx([1, 2, 3]);
z = [1, 2, 3];
xx(z);
z = [1, 2];
xx(1, 2);
xx(z);
def yy (a, b, c = "default") { println "a $a b $b c $c"; };
yy(1, 2, 3);
yy([1, 2, 3]);
z = [1, 2, 3];
yy(z);
z = [1, 2];
yy(1, 2);
yy(z);
This would make the following ambiguous:
def zz (a, b = "default", c = "default") { println "a $a b $b c $c"; };
zz([1, 2, 3]);
There needs to be a way, as with Java varargs, to indicate when an array is "an array of arguments" and when it is "an argument that is an array".
The current, Java-like approach may not be the best. It would be nice to have an "apply" method on functions/closures that would explicitly take "an array of arguments", much like Scheme/JavaScript:
def zz (a, b = "default", c = "default") { println "a $a b $b c $c"; };
zz([1, 2, 3]); // "a [1, 2, 3] b default c default"
zz.apply([1,2,3]); // "a 1 b 2 c 3" |
Show » |
|
def x={Object[] a -> println a}
x(1,2,3)
x(1,2)
if you ant a list to be forced to be expanded, then you can do this by using the star operator:
zz(*[1,2,3]) // a=1,b=2,c=3
but in case of zz the list is used, because you gave zz a list.
So I make this a bug with a higher priority, because yy([1,2]) is not calling the yy method with two arguments.