jashkenas/coffee-script — pull request #2887 by epidemian (2013-03-25 07:02:55+00:00)
Title: Add new mathematical operators

This is an attempt to ([finally](https://github.com/jashkenas/coffee-script/pull/2026#issuecomment-5049478)) include a new set of mathematical operators beyond what JavaScript provides.

Included on this PR are the operators that seemed the most consensually accepted by the community and that seemed the most practical and intuitive in terms of syntax to me:

* the power operator `**`,
* the floor division operator `//` and
* the (correct) modulo operator `%%`.

Other operators might be useful, but i think it's important not to over do it and try to convert every function on `Math` into a new operator. So i deliberately left out more sophisticated operators like LiveScript's chainable maximum and minimum operators (`?`) or a unicode `√` operator for square roots :smile_cat:

That being said, this is an open pull request, so if you think other operators deserve to make it in (or some of these doesn't deserve it), please comment.

----

##### Small caveat

The floor division operator token clashes with the current empty regex token: `//`. I think there's no way to have them both; even if we did some grotesque lexer + parser magic introducing some ambiguity in the lexer (say, a FLOOR_DIV_OR_EMPTY_REGEX token) and then trying to disambiguate it in the parser, there are ugly corner cases, like `a //i`, which is valid on the current master as a call to `a` with an empty regex and is also valid in this PR as a floor division between `a` and `i`.

I opted to remove the support for empty regexes in this PR (notice a missing regex test), but i don't know if this is an acceptable removal. I would expect that nobody would ever use an empty regex, as i see no point in doing so, but i've been very mistaken about guessing what other people _don't_ do on their code in the past. So, if we decide to remove the empty regex token, could we make an intermediate minor release that marks that token as a syntax error and some time after that release these new set of operators?