Copyright © 2003-2005, Peter Seibel
3. Practical: A Simple Database
Obviously, before you can start building real software in Lisp, you’ll have to learn the language. But let’s face it—you may be thinking, “‘Practical Common Lisp,’ isn’t that an oxymoron? Why should you be expected to bother learning all the details of a language unless it’s actually good for something you care about?” So I’ll start by giving you a small example of what you can do with Common Lisp. In this chapter you’ll write a simple database for keeping track of CDs. You’ll use similar techniques in Chapter 27 when you build a database of MP3s for our streaming MP3 server. In fact, you could think of this as part of the MP3 software project—after all, in order to have a bunch of MP3s to listen to, it might be helpful to be able to keep track of which CDs you have and which ones you need to rip.
In this chapter, I’ll cover just enough Lisp as we go along for you to understand how the code works. But I’ll gloss over quite a few details. For now you needn’t sweat the small stuff—the next several chapters will cover all the Common Lisp constructs used here, and more, in a much more systematic way.
One terminology note: I’ll discuss a handful of Lisp operators in this chapter. In Chapter 4, you’ll learn that Common Lisp provides three distinct kinds of operators: functions, macros, and special operators. For the purposes of this chapter, you don’t really need to know the difference. I will, however, refer to different operators as functions or macros or special operators as appropriate, rather than trying to hide the details behind the word operator. For now you can treat function, macro, and special operator as all more or less equivalent.1
Also, keep in mind that I won’t bust out all the most sophisticated Common Lisp techniques for your very first post-“hello, world” program. The point of this chapter isn’t that this is how you would write a database in Lisp; rather, the point is for you to get an idea of what programming in Lisp is like and to see how even a relatively simple Lisp program can be quite featureful.