i++ #41

Open
hakunin opened this Issue Jan 13, 2011 · 4 comments

Projects

None yet

4 participants

@hakunin
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
Member
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.

@baroquebobcat
Member

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

@consiliens
Contributor

"Comment 3 by rogerpack2005, May 28, 2011
++ !"
http://code.google.com/p/mirah/issues/detail?id=19

@baroquebobcat
Member

++ 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