Robby Zambito

23 Jun 2023

Languages that do not use prefix notation are weird

I don’t mean that you should avoid such languages, but rather that they are exceedingly uncommon.

For some reason, prefix notation is often associated with Lisp. In reality, there are very few languages that do not use prefix notation. Off the top of my head, I can only think of Forth, and Postscript. Consider the following:

foo(a, b)

What language is this? Well, it could be C, C++, Java, Javascript, Python, C#…

Great. That looks like a normal procedure call. It could be one of many languages, assuming this is not a complete statement (as it would be missing a semicolon in some languages). Now, what if we remove the useless comma:

foo(a b)

And let’s get a little crazy, and move the opening parenthesis to the begining of the expression:

(foo a b)

What language do we have now? Well, it could be Common Lisp, Clojure, Elisp, Scheme… Generally, it is some dialect of Lisp.

How did we move the operator in relation to the operands? We moved it nowhere.

The only reason that prefix notation is associated with Lisp, is because most other languages have a few inconsistencies. Namely, arithmetic operators like +, -, *, and /. These operators are usually treated in a special way, and given an infix syntax; they are placed between its operands: a + b. In most programming domains, the vast majority of operations are procedure calls - not arithmetic operations. The importance of these operators are blown out of proportion because of how familiar they are. In practice using a function-like notation for them is not a big deal.

The operator is always placed before any operands in Lisp. It does not represent any operators in a special and inconsistent way. Expressions like (+ a b) may look strange at first, but just consider: + is simply the chosen name for the add procedure. If we use the name add instead, we get:

(add a b)

And if we apply the inverse of the previous transformation, we get:

add(a, b)

Which is really not all that strange :)