Next: Extent, Previous: Variable Scoping, Up: Variable Scoping [Contents][Index]
SXEmacs Lisp uses indefinite scope for local variable bindings. This means that any function anywhere in the program text might access a given binding of a variable. Consider the following function definitions:
(defun binder (x) ;xis bound inbinder. (foo 5)) ;foois some other function.
(defun user () ; x is used in user.
(list x))
In a lexically scoped language, the binding of x in
binder would never be accessible in user, because
user is not textually contained within the function
binder. However, in dynamically scoped SXEmacs Lisp, user
may or may not refer to the binding of x established in
binder, depending on circumstances:
user directly without calling binder at all,
then whatever binding of x is found, it cannot come from
binder.
foo as follows and call binder, then the
binding made in binder will be seen in user:
(defun foo (lose) (user))
foo as follows and call binder, then the
binding made in binder will not be seen in user:
(defun foo (x) (user))
Here, when foo is called by binder, it binds x.
(The binding in foo is said to shadow the one made in
binder.) Therefore, user will access the x bound
by foo instead of the one bound by binder.