summaryrefslogtreecommitdiff
path: root/content/posts/languages-that-do-not-use-prefix-notation-are-weird
diff options
context:
space:
mode:
Diffstat (limited to 'content/posts/languages-that-do-not-use-prefix-notation-are-weird')
-rw-r--r--content/posts/languages-that-do-not-use-prefix-notation-are-weird/index.md68
1 files changed, 68 insertions, 0 deletions
diff --git a/content/posts/languages-that-do-not-use-prefix-notation-are-weird/index.md b/content/posts/languages-that-do-not-use-prefix-notation-are-weird/index.md
new file mode 100644
index 0000000..99172b2
--- /dev/null
+++ b/content/posts/languages-that-do-not-use-prefix-notation-are-weird/index.md
@@ -0,0 +1,68 @@
+---
+title: "Languages that do not use prefix notation are weird"
+date: 2023-06-23T00:35:43-04:00
+type: "post"
+draft: false
+tags: [lisp]
+description: "For some reason, prefix notation is often associated with..."
+---
+
+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:
+
+```c
+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 (missing a semicolon in some languages).
+
+Now, what if we remove the useless comma:
+
+```c
+foo(a b)
+```
+
+And let's get a little crazy, and move the opening parenthesis to the begining of the expression:
+
+```lisp
+(foo a b)
+```
+
+Now what language do we have?
+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 given an _infix_ syntax, and it is placed between its operands: `a + b`.
+In most programming domains, the vast majority of operations are procedure calls - not arithmetic operations.
+
+Lisp does not have this inconsistency.
+The operator is always placed before any operands.
+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:
+
+```lisp
+(add a b)
+```
+
+And if we apply the inverse of the previous transformation, we get:
+
+```c
+add(a, b)
+```
+
+Which is really not all that strange :) \ No newline at end of file