0

Please note that this is a genuine question. I'm not rep-whoring. But if anyone feels like closing it like this one please don't close before I get an answer. That said, I'd seriously like to know why Lua doesn't have augmented assignment like most other languages.

> f = 100
> f *= 5
  stdin:1: syntax error near '*'

I understand that language design involves a lot of decisions but when It comes to a question like should we include augment assignment?, the answer to me seems like a no-brainer. If I were to design a language(big if), the first thing to do would be to include all the conventional set of statements and then worry about the rest of the concepts.

I still can't figure out why the folks at Tecgraf decided to not include augmented assignments in Lua. If I were to give an answer to this question I would give some way-of-the-mark reason like augmented assigment would make parsing harder considering Lua's free form syntax. It's a crazy answer, I know, I need someone else's more reasonable opinion or at least a reference that justifies this design decision.

Community
  • 1
  • 1
Plakhoy
  • 1,846
  • 1
  • 18
  • 30
  • Turns out there's an answer [here](http://stackoverflow.com/questions/20091779/lua-operators-why-isnt-and-so-on-defined?rq=1). I was partially right about the parsing thing according to the 2nd point in that link. – Plakhoy Dec 06 '13 at 07:15
  • 4
    This has been asked before even a couple of times on the lua mailing list; you should find it w/ google. The short answer is indeed that's what the designers decided on. I recall reading that the reason was to keep lua syntax simple. If they added `+=` then they'll have to add `-=` `++` `--` etc. where do you draw the line? Note that I don't necessary agree with that design choice but it is what it is. – greatwolf Dec 06 '13 at 08:22
  • Although this doesn't answer your question, I don't imagine it would be that hard to extend the Lua interpreter C implementation to support those, since the code to implement operator priority and arity 1 and 2 is already there. It might be sufficient to plop in the right if block for each new op in the right place, add some new bytecodes for those ops, and a new metamethod name for each. Alternately, you might be interested in moonscript, which uses LPEG to extend Lua syntax in a very nice way. – Oliver Dec 06 '13 at 14:41

0 Answers0