summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobby Zambito <contact@robbyzambito.me>2023-06-23 00:26:01 -0400
committerRobby Zambito <contact@robbyzambito.me>2023-06-23 00:36:55 -0400
commit35550adfc7fa427137bed200696af424df8633da (patch)
treef5f525ee814547dab0208fa91c4f2d3b2edb5c3f
parentaa4d41b88ea43ed42c799d527020bb18aa8633bc (diff)
Added prefix notation post
-rw-r--r--.gitignore2
-rw-r--r--content/posts/languages-that-do-not-use-prefix-notation-are-weird/index.md68
2 files changed, 70 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 4d121c0..f0e1832 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,5 @@ hugo.exe
hugo.darwin
hugo.linux
+# Emacs backup files
+*~
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