jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
Signup
groovy
  • groovy
  • GROOVY-158

Multiple assignment

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

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

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"

Issue Links

is depended upon by

Task - A task that needs to be done. GROOVY-762 implement syntax improvements

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.
relates to

New Feature - A new feature of the product, which has yet to be developed. GROOVY-1543 Support multiple declarations at once: def a,b = 1,2

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

  • All
  • Comments
  • Work Log
  • History
  • Activity

People

  • Assignee:
    blackdrag blackdrag
    Reporter:
    james strachan
Vote (2)
Watch (3)

Dates

  • Created:
    27/Jan/04 6:46 AM
    Updated:
    24/Feb/09 8:58 PM
    Resolved:
    22/Apr/08 7:13 AM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.