
|
If you were logged in you would be able to see more operations.
|
|
|
groovy
Created: 27/Jan/04 06:46 AM
Updated: 22/Apr/08 06:32 PM
|
|
| Component/s: |
GEP
|
| Affects Version/s: |
None
|
| Fix Version/s: |
1.6
|
|
|
Issue Links:
|
Related
|
|
This issue relates to:
|
|
GROOVY-1543
Support multiple declarations at once: def a,b = 1,2
|
|
|
|
|
|
dependent
|
|
|
|
This issue is depended upon by:
|
|
|
|
|
|
|
|
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"
|
|
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" |
Show » |
|
list[a, b, c] = someListExpr
would expand to
t = someListExpr
list[a] = t[0]
list[b] = t[1]
list[c] = t[2]