Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.6-beta-2
-
None
-
None
Description
Groovy's list-indexing semantics originally came from Ruby, where x[2,5] means the same as x[2 ..< 5]. However, at some point it was changed r-values (getAt()), but never for l-values (putAt()). So currently we have this:
x = [4, 5, 6, 7]
assert x[1, 3] == [5, 7]
x[1, 3] = 55
assert x == [4, 55]
If you try to index with a list of any length other than two, you get an exception, but only as an l-value, not an r-value.
The proposal is that x[list1] = list2 should succeed when list1 has the same number of elements as list2, replacing the corresponding elements, and throw an exception otherwise. Also x[list1] = nonlist should replace all elements that have the specified indices with the given nonlist element.
This was discussed on the groovy-dev mailing list, subject "Bug or Feature?", starting Nov. 12, 2008.