aboutsummaryrefslogtreecommitdiffstats
path: root/doc/lispref/variables.texi
diff options
context:
space:
mode:
Diffstat (limited to 'doc/lispref/variables.texi')
-rw-r--r--doc/lispref/variables.texi51
1 files changed, 51 insertions, 0 deletions
diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi
index d9096dac018..4936f7a921a 100644
--- a/doc/lispref/variables.texi
+++ b/doc/lispref/variables.texi
@@ -223,6 +223,18 @@ Here is an example of this: @code{z} is bound to the old value of
223 @result{} (1 2) 223 @result{} (1 2)
224@end group 224@end group
225@end example 225@end example
226
227On the other hand, the order of @emph{bindings} is unspecified: in the
228following example, either 1 or 2 might be printed.
229
230@example
231(let ((x 1)
232 (x 2))
233 (print x))
234@end example
235
236Therefore, avoid binding a variable more than once in a single
237@code{let} form.
226@end defspec 238@end defspec
227 239
228@defspec let* (bindings@dots{}) forms@dots{} 240@defspec let* (bindings@dots{}) forms@dots{}
@@ -1630,6 +1642,45 @@ an ordinary evaluated argument.
1630@end example 1642@end example
1631@end defun 1643@end defun
1632 1644
1645 A variable can be let-bound (@pxref{Local Variables}) to a value.
1646This makes its global value shadowed by the binding;
1647@code{default-value} will then return the value from that binding, not
1648the global value, and @code{set-default} will be prevented from
1649setting the global value (it will change the let-bound value instead).
1650The following two functions allow to reference the global value even
1651if it's shadowed by a let-binding.
1652
1653@cindex top-level default value
1654@defun default-toplevel-value symbol
1655This function returns the @dfn{top-level} default value of
1656@var{symbol}, which is its value outside of any let-binding.
1657@end defun
1658
1659@example
1660@group
1661(defvar variable 'global-value)
1662 @result{} variable
1663@end group
1664@group
1665(let ((variable 'let-binding))
1666 (default-value 'variable))
1667 @result{} let-binding
1668@end group
1669@group
1670(let ((variable 'let-binding))
1671 (default-toplevel-value 'variable))
1672 @result{} global-value
1673@end group
1674@end example
1675
1676@defun set-default-toplevel-value symbol value
1677This function sets the top-level default value of @var{symbol} to the
1678specified @var{value}. This comes in handy when you want to set the
1679global value of @var{symbol} regardless of whether your code runs in
1680the context of @var{symbol}'s let-binding.
1681@end defun
1682
1683
1633@node File Local Variables 1684@node File Local Variables
1634@section File Local Variables 1685@section File Local Variables
1635@cindex file local variables 1686@cindex file local variables