A.i.L. #3: The Glyphs of Lisp
Last updated:Common Lisp uses symbols (I mean the symbols on your keyboard, separate from numbers and letters) in different ways from other languages. And since the word "symbol" in Lisp is a very distinctive concept and not what I am discussing here, it is almost impossible to search for this information. So I am going to use the word "glyphs" for lack of anything better, and as I understand these, this article will expand to describe them all.
' (quote)
The first glyph is the single quote '. It is synonimous with the function named "quote." What it does is to simply prevent evaluation. Recall that lists in Lisp are used for both programs and data. Without additional information, it is not obvious to the program wether a literal list typed into the REPL is one or the other. (1 2 3) may look obviously like a list, but Lisp assumes it is code otherwise, and tries to execute a function named "1."
Quoting a list ensures it is not evaluated.
(quote (1 2 3)) ≡ '(1 2 3)
` (back quote)
The back quote adds one additional behavior to what the quote does, and really needs to be discussed in context with the comma. Besides that behavior, it is equivalent to the quote.
'(1 2 3) ≡ `(1 2 3)
, (comma)
Adding commas inside back quoted forms will behave as if the quote was not there to begin with.
`(1 ,(+ 1 1) 3) ≡ '(1 2 3)
Since quoting a list causes it to not be evaluated, and the comma undoes the back quote, the second item in the list is like there never was a quote. It is evaluated, and the resulting value is placed at that point in the list.
#' (shorthand for function)
(defun foo () (format t "Hello world.~&")) → FOO #'foo ≡ (function foo) ≡ (symbol-function 'foo)
,@ (expands a list in a `)
More to come…