Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
def myMonth(){ [2000, "Jan", 1] }
String month
int day, year
(year, month, day) = myMonth()

Unlike with declarations, the LHS doesn't need to simply be a variable:

Code Block

def map = [a:1, b:2]
(map.a, map.b) = [3, 4]
assert map == [a:3, b:4]

a = 10..15
i = 3
i, a[i] = i+1, 20
assert i == 4 && a[3] == 20 && a[4] == 14 

Other examples which need to work:

Code Block

x = 0
a, b, c = x, (x += 1), (x += 1)
assert [a, b, c] == [0, 1, 2]

year, month, day = "2007-03-20".split('-')

Other assignment operators

These may not be implemented initially, but we attempt to define them here. It includes these:

...

Code Block
yourObject *= 1, 2
// calls the multiply() method on yourObject with the list [1, 2]

As an alternative to the semantics described here, we could define 'a, b *= 3' to be the same as 'a *= 3; b *= 3'. This seems more useful but then if the semantics were to be consistent, then 'a, b = 3' should mean 'a = 3; b = 3'.

Use in Method declarations

...