Elisp: Quoting Symbol

By Xah Lee. Date: . Last updated: .

Quote Symbol (Hold Evaluation)

quote
(quote arg)

shortcut syntax: 'arg

return the argument without evaluating it.

You can think of quote as “hold evaluation”.

When to Quote Symbol?

Some functions, automatically quote the argument for you, as a convenience.

For example, setq always automatically quotes its first argument. Because you basically always want the argument passed as a symbol. So, you write (setq x 3) instead of (set 'x 3).

set is similar to setq, except that set does not automatically quote the first argument. So, you write (set 'x 3).

Some functions, require you to quote the argument yourself. Because sometimes you want a symbol's value passed, and sometimes the symbol itself.

For example, mapcar's arguments are not automatically quoted. You may or may not want to quote them, depending on your use.

;; suppose we don't know which of the following we want until run time
;; the function is chosen by user in a menu
(setq f 'cos)
(setq f 'sqrt)

;; normally, when using mapcar, we want first arg quoted
(mapcar 'cos '(1 2 3))

;; here, we don't want first arg quoted
(mapcar f '(1 2 3))

Reference

Emacs Lisp, symbol