Emacs Lisp Cheat Sheet for Clojure Developers
2023/07/21
This article was written by an AI 🤖. The original article can be found here.
If you want to learn more about how this works, check out our repo.
If you're a Clojure developer looking to learn Elisp, you have a great head start since you already know a Lisp dialect. This concise guide focuses on the main differences between the two languages.
Numeric Types:
- Elisp has integers and floats, which can be mixed in arithmetic functions as expected.
- Unlike Clojure, Elisp doesn't have a ratio type, so integer division works similarly to most other languages.
- Integers can be expressed in multiple ways, and the printed representation of REPL output may look odd at first, but it's simply showing alternate representations of the integer.
- Floats can be expressed in scientific notation, similar to Clojure.
- Elisp allows arbitrarily large integers.
Character Types:
- Elisp has strings and characters, represented and escaped in a similar way to Clojure.
- Character literals are displayed using a '?' prefix.
- Characters are actually integers, but not all integers are valid characters.
- String formatting can be done using the format function, similar to Clojure.
- Messages can be displayed in the minibuffer using the message function, which is also helpful for debugging.
Conditional Logic:
- In Elisp, nil and the empty list '()' are falsy, while everything else is truthy.
- Elisp doesn't have a separate Boolean type; instead, the symbol 't' represents true and 'nil' represents false.
- Predicate functions conventionally have a 'p' suffix, unlike Clojure's '?' suffix.
- Comparison functions like '=' and 'string=' are case-sensitive.
Functions:
- Functions are defined using 'defun', with arguments enclosed in parentheses.
- Docstrings are slightly different in Elisp.
- Variadic functions can be created using '&rest'.
- Elisp doesn't support true multi-arity functions, but optional arguments can be used instead.
Let Forms:
- For let bindings, use 'let*'. Each binding pair needs to be placed in its own list.
- 'let' also exists in Elisp, but it doesn't allow the use of earlier bindings within later ones.
Comments, Namespaces, and Access Modifiers:
- Elisp doesn't have namespaces or access modifiers.
- By convention, packages prefix their functions and variables with a package name prefix.
This cheat sheet provides a quick overview of the main differences between Emacs Lisp and Clojure. It can serve as a handy reference for Clojure developers venturing into Elisp development.