Abstract
The next basic building block we need to look at are variables. Common Lisp supports two kinds of variables: lexical and dynamic.1 These two types correspond roughly to “local” and “global” variables in other languages. However, the correspondence is only approximate. On one hand, some languages’ “local” variables are in fact much like Common Lisp’s dynamic variables.2 And on the other, some languages’ local variables are lexically scoped without providing all the capabilities provided by Common Lisp’s lexical variables. In particular, not all languages that provide lexically scoped variables support closures.
Dynamic variables are also sometimes called special variables for reasons you’ll see later in this chapter. It’s important to be aware of this synonym, as some folks (and Lisp implementations) use one term while others use the other.
Early Lisps tended to use dynamic variables for local variables, at least when interpreted. Elisp, the Lisp dialect used in Emacs, is a bit of a throwback in this respect, continuing to support only dynamic variables. Other languages have recapitulated this transition from dynamic to lexical variables—Perl’s local variables, for instance, are dynamic while its my variables, introduced in Perl 5, are lexical. Python never had true dynamic variables but only introduced true lexical scoping in version 2.2. (Python’s lexical variables are still somewhat limited compared to Lisp’s because of the conflation of assignment and binding in the language’s syntax.)
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Rights and permissions
Copyright information
© 2005 Peter Seibel
About this chapter
Cite this chapter
Seibel, P. (2005). Variables. In: Practical Common Lisp. Apress. https://doi.org/10.1007/978-1-4302-0017-8_6
Download citation
DOI: https://doi.org/10.1007/978-1-4302-0017-8_6
Publisher Name: Apress
Print ISBN: 978-1-59059-239-7
Online ISBN: 978-1-4302-0017-8
eBook Packages: Professional and Applied ComputingProfessional and Applied Computing (R0)Apress Access Books