What is the difference between setq
and defvar
in Emacs lisp?
I see common lisp version of the same question at https://stackoverflow.com/questions/3855862. Are they same in Elisp?
What is the difference between setq
and defvar
in Emacs lisp?
I see common lisp version of the same question at https://stackoverflow.com/questions/3855862. Are they same in Elisp?
You should ask Emacs this question: C-h i
, choose the Elisp manual (m Elisp
), and search the index for "defvar" (i defvar
). That takes you to node Defining Variables.
Emacs tells you that defvar
allows attaching a doc string, and that if the variable already has a value then it does nothing.
It also tells you about the use of defvar
with no value to be assigned: (defvar foo)
. It tells you that that declares the variable to be dynamically scoped.
setq
has none of those properties.
defvar
and setq
are similar, but not quite the same, in Emacs Lisp and Common Lisp.