Hacker News new | ask | show | jobs
by erixM 1246 days ago
What if you have to use the remainder operator? How would "|> % % 2" work?
1 comments

The same way any other infix operator would, the operator has to have an expression on either side so the first % can't be an operator, and you can't have two expressions next to each other anyway i.e. you can't have "x x" or "f(x) x" or "% %"., so the second % has to be the % operator.

Definitely looks strange and could be confusing at first, but the syntax is unambiguous to parse. Add a comment, write "|> (%) % 2" perhaps, or just create a mod function and write "|> mod(%, 2)".