Details
-
Wish
-
Status: Closed
-
Trivial
-
Resolution: Fixed
-
1.0-JSR-1
-
None
-
None
-
Groovy Version: 1.0-jsr-01 JVM: Blackdown-1.4.2-01
Description
In my opinion it would be nice to allow for lvalue slicing using the range operator. Example: reverse the first n elements of a list
// throws IllegalArgumentException
list[0..<n] = list[0..<n].reverse()
The exception is thrown in DefaultGroovyMethods.java ("You must specify a list of 2 indexes to create a sub-list") for all n != 2 (i.e. almost always)
Rewriting the statement as
list[0, n-1] = list[0..<n].reverse()
works but is not as nice.
It might be enough to change DefaultGroovyMethods.java from
if (splice.size() != 2)
{ throw new IllegalArgumentException("You must specify a list of 2 indexes to create a sub-list"); } int left = InvokerHelper.asInt(splice.get(0));
int right = InvokerHelper.asInt(splice.get(1));
to
int left = InvokerHelper.asInt(splice.get(0));
int right = InvokerHelper.asInt(splice.get(splice.length()));
but i'm not sure what other parts are affected 'cause i'm a complete newbie
Thanks
Jochen