Closed mikera closed 10 years ago
This fails because inner-product(x,y) is interpreted as symbol inner minus function-call product(x,y). This is an unfortunate byproduct of allowing 3-4 to be parsed and not requiring whitespaces between literals. I think this is also the reason why in many algol- derived languages like java '-' is not a valid character in a symbol. I am not sure what to do about that. There are multiple strategies:
I think allowing all valid symbol characters clojure allows would be nice to have. I don't see a way to have this without 1.) but introducing it would break many user's expectation that "x-y" can be parsed.
Otherwise 4. would be the strategy I am inclined to. The ability to specify aliases for symbols could also make the infix expression more concise. That would also allow to specify 'values' for some variables in the infix string e.g. Parse this expression with x equals 5.
What would be your favourite way it is handled?
I guess I'd prefer 4) plus some way of quoting symbols to be used literally?
Would also be worth thinking how this might interact with namespacing, ideally the same mechanism would support qualified symbols.
I just pushed a fix to master. It is now supported to escape symbols. Inside the escaped symbols you can use the characters that are allowed in clojure symbols. So you can do the following now:
(parse-expression "inner-product
(a)") ;=> (inner-product a)
please report if it is working for you so I can close the issue.
Looks good to me!
I merged this fix back into develop for you.
Currently expresso does not correctly parse expressions like: