Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.6-rc-2
    • Component/s: GEP
    • Labels:
      None

      Description

      Support for multiple assignment to simulate multiple return types:

      a, b, c = someFunctionReturningAListOfThreeElements()

      If more elements are returned than the number of variables to assign values to, we could get the head of list in the first variable and the rest of the list in the second variable:

      head, tail = [1,2,3,4]
      assert head == 1
      assert tail == [2,3,4]

      Can also be used for variable swapping
      x, y = [y, x]
      x, y = y, x

      We have to be careful with varibale definitions, because currently:
      def a, b, c = someFunctionReturningList()
      because currently, a and b would be null, while c would be assigned to the value of the return of the function.

      A GEP should be created to present all the possibilities, syntax, edge cases.

      Further ideas (subsequent feature enhancements) could be considered like fetching matching groups from regex:
      def regex = ~/firstname: (.), name: (.)/
      firstname, name = ("firstname: Guillaume, name: Laforge") =~ regex)
      assert firstname == "Guillaume"
      assert name == "Laforge"

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                blackdrag Jochen Theodorou
                Reporter:
                jstrachan james strachan
              • Votes:
                2 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: