8 ms·
Even still, mathematics isn't entirely infix. And outside computer algebra systems, you'll be hard pressed to find examples of the postfix operations expressed
by Jtsummers 11y ago
Even still, mathematics isn't entirely infix. And outside computer algebra systems, you'll be hard pressed to find examples of the postfix operations expressed as postfix in programming environments. !, for example. What language allows you to express:
n P k = n! / (n - k)!
as the above? `n P k` will become something like `nperms n k`, factorial will be moved to prefix as `fact n / fact (n - k)`. We're already diverging from the domain language, there's no reason to consider a more logically consistent framework in this case than one that seems to have arbitrarily moved some things from infix to prefix, postfix almost universally to prefix, and left some infix as infix.
- xrange 11y ago>What language allows you... SML allows you to have an infix function named "P", and Haskell allows something similar, although you have to quote it with backticks and can't use a capital letter to start a function name... https://en.wikibooks.org/wiki/Standard_ML_Programming/Expressions#Infix_function_calls https://en.wikibooks.org/wiki/Standard_ML_Programming/Expres... https://wiki.haskell.org/Infix_operator#Using_prefix_functions_with_infix_notation https://wiki.haskell.org/Infix_operator#Using_prefix_functio...
- Jtsummers 11y agoI did mean to mention that, but how about creating postfix operators?
- xrange 11y agoIn Prolog you have the ability to create new postfix operators. Of course Prolog being a logic language and not a functional language, along with '!' being used for 'cut' opens up another can of worms. http://www.swi-prolog.org/pldoc/man?predicate=op/3 http://www.swi-prolog.org/pldoc/man?predicate=op/3
- lmm 11y agoYou're right as far as you go, but it's not an all-or-nothing thing. Most languages won't let you write mathematics exactly like mathematicians do, but the closer you can get the better. For many cases avoiding infix entirely would be a big cost. (FWIW Scala allows postfix operators, though you'd have to put the n! in brackets)
- sklogic 11y ago> Most languages won't let you write mathematics exactly like mathematicians do, but the closer you can get the better See Wolfram Mathematica for example. Also, one of my usual DSL tricks is to allow arbitrary TeX in identifiers, which, combined with the literate programming tricks, allows to write very idiomatic mathematical expressions as a code.