[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Defvaralias and lexical binding
From: |
BT Templeton |
Subject: |
Defvaralias and lexical binding |
Date: |
Fri, 10 Jun 2011 20:14:37 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
Aliases for lexically-bound variables don't behave as I expected them
to. The 'defvaralias' documentation says that aliased variables "always
have the same value" (docstring) and that they "always share the same
value and the same bindings" (Info), which is true for non-void special
variables, but apparently not for lexically-bound variables or void
special variables. Here's an IELM session with some examples (with
lexical-binding enabled):
ELISP> (defvaralias 'foo1 'bar1)
bar1
ELISP> (let ((bar1 42)) foo1)
*** Eval error *** Symbol's value as variable is void: foo1
ELISP> (progn (defvar foo1) (defvar bar1))
bar1
ELISP> (let ((bar1 42)) foo1)
*** Eval error *** Symbol's value as variable is void: foo1
ELISP> (defvar bar1 0)
bar1
ELISP> (let ((bar1 42)) foo1)
42
ELISP> (defvaralias 'foo2 'bar2)
bar2
ELISP> (let ((foo2 23)) bar2)
23
ELISP> (let ((foo2 17)) (setq bar2 23) foo2)
23
ELISP> (let ((bar2 23)) (setq foo2 17) bar2)
23
I expected the third and fourth expressions to both evaluate to 42 --
especially since 'foo1' and 'bar1' should both be special in the latter
case. Is this a bug?
dankon,
BT
--
Inteligenta persono lernas la lingvon Esperanton rapide kaj facile.
Esperanto estas moderna, kultura lingvo por la mondo. Simpla, fleksebla,
belsona, Esperanto estas la praktika solvo de la problemo de universala
interkompreno. Lernu la interlingvon Esperanton! http://lernu.net/
- Defvaralias and lexical binding,
BT Templeton <=