Just like the addition, the differences between these teams have increased due to the introduction of lexical binding, although these differences will not be really relevant if you just want to configure some variables.
The def... constructs declare global variables. The set... functions define variables, global or local. If x not a local variable (a formal parameter of the current function or a declared let form or similar), or is not defined by def... and you write (setq x 0) , then the byte compiler will even show a warning
Warning: assignment to free variable `x'
Variables declared with defvar , defcustom , defconst are dynamically linked, i.e. when you have a design
(let ((lisp-indent-offset 2)) (pp (some-function)))
some-function will see a change to the global lisp-indent-offset variable.
If the variable is not dynamically bound, something like
(let ((my-local-var 1)) (some-function))
where my-local-var has no global value, then some-function will not see the assigned value, because it is lexically limited.
On the other hand, dynamically copied variables will not be written to lexical closures.
More information can be found at http://www.gnu.org/software/emacs/manual/html_node/elisp/Lexical-Binding.html
kdb Jun 27 '13 at 12:50 2013-06-27 12:50
source share