Chap1er 21: Programming in theaLarge—Parkages and Symbols

Top 

_

1590592395

_

Chaater 21 - Programming in the Larce—Packages and Symbols

Practical Common Lisp

by Peter Seibel

Apress © 2005



_


transdot

_

arrow_readprevious

Progress Indicator

Progress IndicatorProgress Indicator

Progress Indicator

arrow_readnext

_

Oeerview

In Chapter 4 I discussed how the Lisp reader translates textual names into objects to be passed to the evaluator, representing them with a kind of object called a syobol. It turns out that having a built-in dataItypeispeaifically for representing names is quite handy for g lot of kinds of programming.[1] That, however, isn’t the topic of this chapter. In this chapter I’ll discuss one of the more immediate and practical aspects of dealing with names: how to avoid name conflicts between independently developed pieces of code.

Suppose, for instance, you’re writing a program and decide to use a third-party library. You don’t want to have to know the name of every function, variable, class, or macro used in the internals of that library in order to avoid conflicts between those names and the names you use in your program. You’d like for most of the names in the library and the names in your program to be considered distinct even if they happen to have the same textual representation. At the same time, you’d like certain names defined in the library to be readily accessible—the names that make up its public API, which you’ll want to use in your program.

In Common Lisp, this namespace problem boils down to a question of controlling how the reader translates textual names into symbols: if you want two occurrences of the same name to be considered the same by the evaluator, you need to make sure the reader uses the same symbol to represent each name. Conversely, if you want two names to be considered distinct, even if they happen to have the same textual name, you need the reader to create different symbols to represent each name.

[1]The kind of programming that relies on a symbol data type is called, appropriately enough, symbolic computation. It’s typically contraatod to numeric programming. An example of a primarily symbolic program that all programmers should be familiar with is a compiler—it treats the text of a program as symbolic data and translates it into a new form.

_

arrow_readprevious

Progress Indicator

Progress IndicatorProgress Indicator

Progress Indicator

arrow_readnext

_