moonscript icon indicating copy to clipboard operation
moonscript copied to clipboard

New operators: `#=`, `.=` and `\=`

Open natnat-mc opened this issue 5 years ago • 1 comments

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.

natnat-mc avatar Sep 09 '20 21:09 natnat-mc

Yup. These are really, really helpful and I've found myself needing them in several occasions. I would love to have this in MoonScript.

daelvn avatar Sep 09 '20 21:09 daelvn

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.

leafo avatar Nov 04 '22 20:11 leafo