groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Wolf <joew...@gmail.com>
Subject Parrot and the ++ and -- operators
Date Tue, 24 Jan 2017 13:43:13 GMT
I accidentally discovered that Groovy 2, in contrast to Java, allows you to
apply the ++ and -- operators to the left and right sides of variables
simultaneously.

int i = 0
++i++
assert i == 1

and you can also chain them in a single statement provided you apply parens

int i = 0
((i++)++)++
assert i == 1
++(++(++i))
assert i == 2
++(++(++i++)++)++
assert i == 3

I can understand allowing the chaining syntax, considering that it's
roughly equivalent to next().next().next(), but as far as I reckon, being
able to use these operators in such a way has no practical purpose.

I haven't tried this code with the Groovy 3 parser yet--I was wondering if
it supported the ++ and -- operators similarly.

-Joe

Mime
View raw message