[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
What's the difference between (defvar foo) and (declare (special foo)),
From: |
Dmitry Gutov |
Subject: |
What's the difference between (defvar foo) and (declare (special foo)), with lexical-binding on? |
Date: |
Sun, 27 Jul 2014 06:32:44 +0300 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 |
1. Save a.el and b.el to the same dir.
2. Open b.el, type M-x eval-buffer.
3. Evaluate (b-foo), see 4 in the echo area.
Note that the assertion in `b-bar' succeeds, and so while `a-a' is not
globally bound, it's visible from `b-bar'.
If I replace the definition of b-bar with
```
(defvar a-a)
(defun b-bar ()
(cl-assert (= a-a 4))
(let ((a-a 5))
(a-bar)))
```
or even with
```
(defun b-bar ()
(defvar a-a)
(cl-assert (= a-a 4))
(let ((a-a 5))
(a-bar)))
```
(which apparently doesn't make `a-a' globally defined in that file, ref.
http://debbugs.gnu.org/18059)
then, as I'd expect, after M-x eval-buffer, (b-bar) evaluates to 5.
Why does this happen? Is (defvar foo) the recommended option to use with
lexical-binding on?
-- Dmitry
a.el
Description: Text Data
b.el
Description: Text Data
- What's the difference between (defvar foo) and (declare (special foo)), with lexical-binding on?,
Dmitry Gutov <=