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
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6-beta-2
    • Fix Version/s: 1.7-beta-1
    • Component/s: None
    • Labels:
      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.

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        12d 2h 33m 1 Martin C. Martin 29/Dec/08 11:56
        Resolved Resolved Closed Closed
        290d 5h 21m 1 Paul King 15/Oct/09 18:17
        Mark Thomas made changes -
        Workflow jira [ 12970108 ] Default workflow, editable Closed status [ 12977866 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12732210 ] Default workflow, editable Closed status [ 12744074 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Martin C. Martin made changes -
        Field Original Value New Value
        Fix Version/s 1.6 [ 13832 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 1.7-beta-1 [ 14014 ]
        Resolution Fixed [ 1 ]
        Martin C. Martin created 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:

              Development