|CHAPTER 7: PACKAGES
Read Chapter 7, and refer to these Corrections as you come to the
appropriate pages. Try all the interactions for yourself as you read
about them, especially because there may be small differences in the
output. It is extremely important to change packages when directed by
the interactions in the book, or else the later interactions won't
Footnotes 1 and 2 on page 44 speak of a "new Common Lisp standard".
This standard is now in effect, and versions of Common Lisp that abide
by it are called "ANSI Common Lisp". The ACL we are using is
an ANSI Common Lisp. This will not make much of a difference in the
version of the text you are using, nor in this course. However, it
does make a difference in the use of packages, which will mostly be
felt in this chapter and in Chapter 12.
page 45, line 3: Change
lisp). That is, the quote mark is no longer to be used.
However, it's even more convenient to use the acl top-level listener
:pa as in
USER(61): :pa lisp
CL is a "nickname" of the common-lisp package.)
From now on, when the book tells you to use the function
in-package use the
:pa command instead and,
save some typing!
page 45, line 14, 15: When the book says to type
user::frank you can continue to do so, even though the
package is now officially named
user is a nickname of the
lisp, along with
a nickname of the
page 46, line -7:
still needs its argument quoted, so follow the book here, and enter
page 47, line 13: It is no longer correct that "The
in-package function will create a new package if necessary."
New packages must be defined by using
you need to do
USER(77): (defpackage test)
#<The TEST package>
> :pa test
page 48, line 8:
needs its argument quoted.
page 49, line -2 - page 50, line 2:
also take the same symbol used by
in-package, but it has
to be quoted:
TEST(92): (find-package 'test)
#<The TEST package>
page 50, lines 5-10:
make-package still exists, but let's
get used to using
defpackage. So change
Packages may be created by
in-package, as we have seen.
A package may also be created by the function
make-package. The difference is that
in-package also changes the
package we are in, whereas
> (make-package "foo")
#>Package foo 12760773>
Recall that packages are created by
defpackage, but that
defpackage does not change the package we are in.
TEST(94): (defpackage "foo")
#<The foo package>
page 50, line -12: Change
- By now, you should have tried all the interactions of Chapter 7,
as requested by Exercise 7.1. Be sure to return to the
common-lisp-user package before going on to the other exercises.
- Exercise 7.3
- When you try to import
user:bill into the
test package, you should get the following response:
Error: Importing these symbols into the TEST package causes a name conflict:
[condition type: PACKAGE-ERROR]
Restart actions (select using :continue):
0: Import these symbols with Shadowing-Import.
1: Return to Top Level (an "abort" restart)
2: Abort #
Your choices are now to enter one of the following:
:cont 0 to have
test::bill so that
user:bill is available in
test package, the old
disappears, and now
cont: 1 to abort the attempted
and return to the top-level listener. (Equivalent to entering
:cont 2 to kill the ACL process entirely.
:cont 1, or
:res Do not kill the ACL process, because you want to
continue right on to Exercise 7.4 in the current environment.
- For Exercise 7.4, you should be in the
package and do the following:
(describe 'pi) again
- describe the
pi in the
package without leaving the
The technique shown in this exercise is the way to "shadow"
a symbol in one package that would normally be available from another
package, so that you can introduce a symbol in this package with the
same name. You will use this technique extensively in the rest of this
course, so that you can define your own version of Common Lisp functions.
In fact, try this, as Exercise 7.4.5:
While still in the
test package do
Now try to evaluate
You should get an error message.
length you typed is
which is not the name of a function. Notice that you are given an
opportunity to use
COMMON-LISP:LENGTH instead. Take this
option by entering
You should see the result (
3) and another top-level prompt.
C-c C-p put your form
into the current line of the Lisp listener, and edit it so that it is
a call to
lisp:length instead, and try that. It should work.
- Do Exercise 7.5 immediately after doing Exercise 7.4.5, and exactly as
instructed. Students in the past have found this exercise very
confusing. Here is the situation:
- After exporting
test::pi there are two symbols
- Since every new package inherits the external symbols of the
common-lisp package, when you change into the
foo package, the
pi that's available is
- However, when you do
pi that's available in the
lisp:pi is shadowed.
lisp:pi may still be used in the
foo package by using its full qualified
Now, create a file named
ch7.cl, and paste into it the
interactions you have been having with the Lisp listener as you worked
on Exercises 7.3, 7.4, 7.4.5, and 7.5. Submit this file, and go on to
Chapter 8. You shouldn't find that as confusing as this chapter may