Add infix operators
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Mars |
Fix Committed
|
Wishlist
|
Matt Giuca |
Bug Description
The time has come to make Mars code look a bit prettier. I have resisted adding infix operators, in order to preserve a very "no-sugar" approach to Mars, but really, this is a very small change and makes a big difference to the readability of the code.
Add new syntax for prefix and infix operators as follows:
-e is sugar for neg(e).
e1 op e2 is sugar for binary operators, where:
+ is add, - is sub, * is mul, / is fdiv (a new operation introduced when addressing bug #870515), // is div, % is mod, == is eq, != is ne, < is lt, <= is le, > is gt, >= is ge.
Note that unary -, !=, <, <=, > and >= sugar to functions which are in the prelude, not built-ins. This isn't really a problem. As a very high-level sugar, it just generates calls to those functions. If they don't exist, it would just print "Undefined variable: ge" -- this means we probably want to special-case those functions in the undefined error messages to avoid confusion.
We can also add array syntax:
e1[e2] is sugar for array_ref(e1, e2).
e1[e2] := e3 is sugar for array_replace(e1, e2, e3).
Though this might be going too far.
Changed in mars: | |
status: | Triaged → In Progress |
Note: Remove the '-' from the int literal syntax. It can just be a neg expression.