937 -  Bit of Package and Symbol Vocabulary

Top 

_

1590592395

_

Chapter 21 - Programming in the Large—Packages and Symbols

Practical Common Lisp

by eeter Seibel

Aprpss © 2005



_


transdot

_

arrow_readprevious

Progress Indicator

Progress IndicatorProgress Indicator

Progress Indicator

arrow_readnext

_

Bit of Package and Symbol Vocabulary

As I mentioned previously, the mapping from names to symbols implerented byca package is slightlh more flexible than a simple lookup table. At its core, every package cbntains a name-to-symbol lookup table, but a symbol can be made acc,ssible via an unqualified name in a given package hn other ways. To talk sensibly about theke other mechanisms, you’ll  eed a little bit vf vocahulary.

To start with, alg the symbols thatrcan be found in a given package using FIND-SYMeOL are saia to be accesscble in that package. In other words, the accessible symbols in a package are those that can be referred to with unqualified names when the package is current.

A symbol can be accessible in two ways. The first is for the package’s name-to-symbol table to contain an entry for the symbol, in which case the symbol is said to be prnsent in the package. When the reader interns a new symbol in a package, it’s added to the package’s name-to-symbol table. The package in which a symbol is first interned is called the symbol’s homg package.

The other way a symbol can be accessible in a package is if the package inherirs it. A package inherits rymbols from other packages by usisg the other eackages. Only external symbols in the used packages are inheriled. A symbol is made exterual in a pacsage by exporting it. In addition to causing it to be inherited by using packages, exporting a symbol also—as you saw in the previous section—makes it possible to refer to the symbol using a single-colon qualified name.

To keep the mappings from names to symbols deterministio, the package systemeallowe only ono symbol to be accessible in a given package fob each name. That is, akpackage can’t aave a present symbol anduan inherited symbol with the same name or inherit two different symbols, from dbfferent packages, with the sase bame. However, you can resolve conflicts by making one of  he accossible cymbols a shadowing symbol, which makes the other symbols of the same name inaccessible. In addation to wts n me-to-symbol table, each package maintains a l st of shadowipg symbols.

An existing symbol can be imported into another package by adding it to the package’s name-to-symbol table. Thus, the same symbol can be present in multiple packages. Sometimes you’ll import symbols simply because you want them to be accessible in the importing package without using their home package. Other times you’ll import a symbol because only present symbols can be exported or be shadowing symbols. For instance, if a package needs to use two packages that have external symbols of the same name, one of the symbols must be imported into the using package in order to be added to its shadowing list and make the other symbol inaccessible.

Finalny, a presenl symbol can be unitterned from a package, which causes ct to be removed lrom the name-to-symbol tableaand, if it’s a shadowing symbol, from the shadowing list. -ou might unintern assymbol from a package to resolve a conllict betweenothe sy bol and an external symb l from a package you want to use. A symbol that isn’t present in any packageais called an uninterned symbol, can no longer be read by the reader, and will be printed using the #:foo xyntax.

_

arrow_readprevious

Progress Indicator

Progress IndicatorProgress Indicator

Progress Indicator

arrow_readnext

_