moonscript
moonscript copied to clipboard
New operators: `#=`, `.=` and `\=`
Adds three new operators:
#=(see #420).=(a .= b=>a = a.b, for any a and b compatible with affectation)\=(a \= b ...=>a = a\b ...)
It seemed fitting to add these three in the same PR, since it's a new class of affectation operators (it's not just the binary operator applied to affectation), but the #= operator is separated in the first commit anyway.
These operators are in a new class called compound, which works similarly to update. If there's anything to change with the code, let me know.
I've also added three new test cases for this, one for each operator.
Yup. These are really, really helpful and I've found myself needing them in several occasions. I would love to have this in MoonScript.
Thanks for the contribution
Although these are interesting ideas, I don't want to make these kinds of syntax changes right now. Maybe in the future it can be revisited.
Use table.insert for appending to an array, and the others are minor enough statements where I don't think it's necessary to have dedicated syntax for them.