i++ #41

hakunin opened this Issue Jan 13, 2011 · 4 comments


None yet

4 participants

hakunin commented Jan 13, 2011

I often find myself in need of i++, for example:

i = 0
rows.each { |row|
  row_class = (i % 2 == 0) ? "even" : "odd"
  html += "..."
  i += 1

Writing i += 1 sucks. Also i++ seems to be more expressive because I don't mean to add one, I man to increment.

headius commented Jan 13, 2011

I agree. I have never liked the lack of i++ in Ruby, and I don't buy that it's misleading to make it an alias for "i += 1".

Java itself makes no explicit guarantees about ++ atomicity, making it atomic for local variables (iinc bytecode) and non-atomic for fields or array elements. So for us, making ++ follow the same atomicity guarantees seems quite reasonable.


How hard would it be to do this, do we want it in 0.0.8?


"Comment 3 by rogerpack2005, May 28, 2011
++ !"


++ does this currently:

$ mirah -e "i=1;i++"
expected terms before '++' (at line: 1, char: 5)

I think it's because it's not in the grammar yet. I think you change the grammar through this file ( https://github.com/mirah/mirah-parser/blob/master/src/mirahparser/impl/Mirah.mmeta ) in the mirah-parser project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment