groovy
  1. groovy
  2. GROOVY-3210

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

    Details

    • 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:
      None
    • Number of attachments :
      0

      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.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Martin C. Martin
            Reporter:
            Martin C. Martin
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: