What is the danger of assigning a free variable in Emacs Lisp?

Adding (setq foo 1)to the code without specifying a variable foousing defvarwill result in the following warning generated by the Emacs byte compiler:

assignment to free variable `foo'

What are the dangers associated with assigning such a free variable without prior definition?

+4
source share
1 answer

Emacs Lisp defaults to Dynamic Linking , so when you write

(defun my-fun-1 (...)
  ...
  (setq foo 1)
  ...)

and get your warning, the code is equivalent (defvar foo)before defun.

This means that the my-fun-1above shares the value foowith

(defun maybe-start-ww3 ()
   (when (= 1 foo)
     (launch-missiles)))

; ELisp . , (, date) , .

, , . , defvar , - , - , .

+7

Source: https://habr.com/ru/post/1614977/


All Articles