4 ms·
No. There are three fundamental ways to encode a syntax tree - prefix, infix, and postfix. Haskell (ML) is prefix, Lisp is infix, and Forth is postfix. (I.e. Fo
by js8 5y ago
No. There are three fundamental ways to encode a syntax tree - prefix, infix, and postfix. Haskell (ML) is prefix, Lisp is infix, and Forth is postfix. (I.e. Forth-like is the opposite of ML-like, not Lisp-like.)
The advantage of infix is that you don't need to know the argument counts for functions/macros to reconstruct the tree, but the disadvantage is extra parens.
I am slowly coming to (subjective) conclusion that postfix is the most natural, because it's the same as the (typical) evaluation order.
- moonchild 5y agoWhy should I concern myself with the order of evaluation? I want to think about my programs from the top down, not the bottom up. What about laziness, which disrupts this apparent order and in fact evaluates from the outside in?
- js8 5y agoYou don't have to anything, I said it's subjective. I prefer ML-like to Lisp-like, because I want typechecking anyway (which involves counting arguments) and this means most Lisp parens we can dispose of. And lately, I noticed I use a lot of "$" (apply) in my code, and while it reads left-to-right, it mostly evaluates right-to-left. So why not switch to Forth-like, which reads and (mostly) evaluates left-to-right?
- dreamcompiler 5y ago> Haskell (ML) is prefix, Lisp is infix, and Forth is postfix. With respect, no. Lisp is by default prefix (Polish notation) but with some work you can make it behave as infix or postfix. Haskell is naturally either prefix or infix depending on how you define and call your functions (the use of backticks or parens around the function name in a call changes it from prefix to infix and vice-versa. It's a rather elegant solution to the problem.) As you stated Forth is postfix (Reverse Polish notation).