groovy (moved to ASF)
  1. groovy (moved to ASF)
  2. GROOVY-3210

When list is indexed with a list, make semantics of r-value (getAt()) and l-value (putAt()) consistent


    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6-beta-2
    • Fix Version/s: 1.7-beta-1
    • Component/s: None
    • Labels:
    • Number of attachments :


      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.


        There are no comments yet on this issue.


          • Assignee:
            Martin C. Martin
            Martin C. Martin


            • Created: