next up previous contents
Next: Numbers Up: Improvements in Common Previous: Symbols

Packages

XLISP now uses the Common Lisp package system for name space management. The functions apropos , apropos-list , intern , and unintern  have been modified accordingly.

A package is a collection of symbols, with some symbols considered internal and others external, or exported. The system is always ``in'' some package, the current package, which is the value of the variable *package* . Packages can ``use'' other packages. When in a package, all symbols of that package, internal or external, and all external symbols of other packages used by that package are considered accessible. Accessible symbols can be referenced by their name and are printed using only their name. Inaccessible symbols can still be referenced and printed using a package name qualifier and a colon, :, or double colon, :: separator. An external symbol in a package is referenced or printed as <package>: <name>

and an internal symbol as <package>:: <name>

Thus foo:bar is the external symbol with name "BAR" in the package named "FOO", and foo::baz is the internal symbol with name "BAZ" in the "FOO" package.

The default package is the package named "USER". This package has several nicknames that can be used to refer to it:

> (package-nicknames "USER")
("CL-USER" "COMMON-LISP-USER")
It uses the "XLISP" package,
(package-use-list "USER")
(#<Package XLISP>)
> (package-nicknames "XLISP")
("CL" "COMMON-LISP" "LISP")
Another standard package is the "KEYWORD" package. Keywords are placed in this package as internal symbols and are made constants with values equal to themselves. Symbols in this package are always referenced and printed as a colon followed by the symbol name. So :test is the symbol with name "TEST" in the keyword package.

Packages are usually constructed using the defpackage  macro. The current package is usually set with the in-package  macro. Both typically appear in a file, followed by some export commands. For example, a file containing the lines

(defpackage "MYPACK" (:use "XLISP"))

(in-package "MYPACK")

(export '(a b))

(defun a () ...)
(defun b () ...)
(defun c () ...)
(defun d () ...)
constructs a new package "MYPACK" with external symbols a and b and internal symbols c and d. It is not necessary to save and restore the old package since the load  function restores the current package to the value it had before the load.

When a package other than the "USER" package is the current package, the standard listener top level loop adds the package name to the prompt:

> (in-package "XLISP"")
#<Package XLISP>
XLISP> (in-package "USER")
#<Package USER>
>

Other functions and macros to support the use of packages are

Details of the assignment of system and statistical symbols to packages and of package naming are likely to change in the near future and should not be relied upon.


next up previous contents
Next: Numbers Up: Improvements in Common Previous: Symbols



Luke Tierney
Wed Feb 26 05:25:18 CST 1997