Книга: Practical Common Lisp
Three Standard Packages
Three Standard Packages
In the next section I'll show you how to define your own packages, including how to make one package use another and how to export, shadow, and import symbols. But first let's look at a few packages you've been using already. When you first start Lisp, the value of *PACKAGE*
is typically the COMMON-LISP-USER
package, also known as CL-USER
.[222] CL-USER
uses the package COMMON-LISP
, which exports all the names defined by the language standard. Thus, when you type an expression at the REPL, all the names of standard functions, macros, variables, and so on, will be translated to the symbols exported from COMMON-LISP
, and all other names will be interned in the COMMON-LISP-USER
package. For example, the name *PACKAGE*
is exported from COMMON-LISP
—if you want to see the value of *PACKAGE*
, you can type this:
CL-USER> *package*
#<The COMMON-LISP-USER package>
because COMMON-LISP-USER
uses COMMON-LISP
. Or you can use a package-qualified name.
CL-USER> common-lisp:*package*
#<The COMMON-LISP-USER package>
You can even use COMMON-LISP
's nickname, CL
.
CL-USER> cl:*package*
#<The COMMON-LISP-USER package>
But *X*
isn't a symbol in COMMON-LISP
, so you if type this:
CL-USER> (defvar *x* 10)
*X*
the reader reads DEFVAR
as the symbol from the COMMON-LISP
package and *X*
as a symbol in COMMON-LISP-USER
.
The REPL can't start in the COMMON-LISP
package because you're not allowed to intern new symbols in it; COMMON-LISP-USER
serves as a "scratch" package where you can create your own names while still having easy access to all the symbols in COMMON-LISP
.[223] Typically, all packages you'll define will also use COMMON-LISP
, so you don't have to write things like this:
(cl:defun (x) (cl:+ x 2))
The third standard package is the KEYWORD
package, the package the Lisp reader uses to intern names starting with colon. Thus, you can also refer to any keyword symbol with an explicit package qualification of keyword
like this:
CL-USER> :a
:A
CL-USER> keyword:a
:A
CL-USER> (eql :a keyword:a)
T
- 21. Programming in the Large: Packages and Symbols
- The Standard Oil Company. Компания Стандард Ойл
- Part Three - Latent Ambiguities
- Fedora FTP Server Packages
- The Standard Library and the Vaults of Parnassus
- Using yum to Remove Packages
- 1.4. Standards and Relevant Bodies
- 1.4.1. Linux Standard Base
- 6.1.1. FHS: File System Hierarchy Standard
- Windows Embedded CE Standard Shell
- 3.2.4. A Comparison of the Three Algorithms
- 4.1.3. Design Issues for Threads Packages