In the emacs init file in one case I use: (show-paren-mode t)
show-paren-mode
is a function. It accepts t
as an argument. Using C-h f show-paren-mode
, the description says,
With a prefix argument ARG, enable Show Paren mode if ARG is positive,
and disable it otherwise.
Behind the scenes, t
is used as a toggle for a mode (some set of behaviors). This call is not setting a variable (explicitly, anyway).
In another case I use: (set 'inhibit-startup-message t)
or (setq inhibit-startup-message t)
setq
is a convenience function for set
.
In Lisp, broadly speaking, there is code and there is data. However, code may be interpreted as data using quoting. The interpreter does not work directly with the source code but with Lisp objects. At a high level, the programmer writes the source code using symbols and lists as well as other data structures like vectors. At a low level, Emacs Lisp subroutines (a.k.a. built-in functions) generate and manage objects: data types and instructions.
To understand this, let's walk through how the statement (set 'inhibit-startup-message t)
is interpreted. Note this is not exactly how it works; some details are omitted to avoid getting too far into the weeds.
Okay, let's go into the weeds a little bit. Lisp works with symbols. A symbol is kind of like a container for a variable part and a function part. A symbol has a name and when that name is referenced, depending on the context, the Lisp interpreter knows whether to use the variable part or the function part. To be clear, the symbol is the "word on the page" (the source code) whereas the meaning of the "word on the page" is the variable part (any Lisp object) or the function part (a Lisp function object).
+----------------+---------------+
symbol (word on page) ---> | variable part | function part |
+----------------+---------------+
+----------------+---------------+
foo ---> | "bar" | do some thing |
+----------------+---------------+
For example, we might have a symbol foo
. The symbol is the "word on the page" f-o-o
. As a variable, it contains the string "bar"
. As a function, it does some action like, printing a message or turning on the coffee maker.
Okay, that's enough of getting into the weeds. How does the Lisp interpreter understand (set 'inhibit-startup-message t)
?
Say you put your cursor to the right of the right paren and press C-x C-e
(eval-last-sexp
). This evaluates the previous expression. The Lisp interpreter goes to the start of the expression, the left parens. It says, "Okay, I've got a list here. That's the beginning of a lisp statement." The interpreter will continue reading until the right paren, at which point it will try evaluating.
The interpreter then sees the set
symbol. It says, "I see a symbol here, but what does it mean?" Since there is no quote preceding the set
word, the interpreter understands it to be a function. Indeed, the first symbol in a list is interpreted as a function name. Looking at C-h f set
, the set function accepts a SYMBOL and a NEWVAL.
The next item is 'inhibit-startup-message
. Since this is preceded by a quote, the interpreter uses the same symbol inhibit-startup-message
.
Therefore, the program can act on the symbol itself (the program can modify this object). The symbol can thus define its function (maybe void?) or its value in the code, e.g. a counter indicates a change in value. The quoted symbol can be passed as an argument to a function to create code at runtime (evaluated as a variable or a function). Otherwise, without the quote, the symbol is evaluated as a variable so the real argument is the variable's value. Keep in mind that a symbol is a kind of placeholder.
The t
is then read. Since this is not quoted, t
is understood to be a variable. In this case, t
is a specific symbol that evaluates to itself (the evaluation returns the same object).
Finally, the right paren is met, and the whole statement is evaluated. Remember, the set
function takes two arguments, SYMBOL and NEWVAL. The SYMBOL argument is inhibit-startup-message
and the NEWVAL argument is t
, which evaluates to t
. The set
function does its black-box behavior and the symbol inhibit-startup-message
gets t
for its variable part.
In the case of (setq inhibit-startup-message t)
, the interpreter knows that because setq
is being used, the next symbol it encounters refers to the same "symbol object". No need to quote it! Now that's convenience!
(info "(eintr) set & setq")
.