4 ms·
Mm, fair point. Infix math rears its ugly head again. I've been living in Lisp a bit too long. Never mind. Actually, let's double down: Instead of writing 1+2
by sillysaurus3 9y ago
Mm, fair point. Infix math rears its ugly head again. I've been living in Lisp a bit too long.
Never mind.
Actually, let's double down: Instead of writing 1+2, you should really be writing +(1 2). Don't you see how much easier that would make things? A single, uniform syntax everywhere! + is just a function that gets called like anything else! Your foo(x -y) example would become foo(x -(y)).
I'm mostly joking.
- dasmoth 9y agoHaskell makes a reasonable job of combining infix operators with no commas between function arguments[1]. You sometimes end up with a few extra parentheses and $s instead, but things generally seem to work out. Does use commas for lists and tuples, though. The latter kind-of make sense, it's the commas that identify the expression as a tuple. Not sure what the rationale for commas in lists is, though. [1] Slightly complicated by currying (arguably, it's several successive function applications rather than one multi-arg application) but the end result is the same...
- tromp 9y ago> Not sure what the rationale for commas in lists is, though. Well, you need some separator, and spaces won't do since [x y] has x applied to y.
- Houshalter 9y agoIt's not infix math that's the problem, it's the ambiguity of "-". It can take two arguments in one context, or one in another (or just be a representation of a negative number without implying any function call at all.) If we just used a different symbol for subtraction, it would clear up a number of other parsing problems languages run into. Or you could just require negations to be done inside parentheses.
- coldtea 9y agoOr just require whitespace for binary - and no whitespace for unary. res = -x ==> negative x res = c - x ==> c minus x res = - x ==> syntax error