next up previous
Next: Random Number Generators Up: Additions Since First Release Previous: Byte Code Compiler

Packages

High level languages like S, ML, or Lisp are most effective when they are used to build collections of small functions which are then combined and reused in building more sophisticated functions. A useful guideline is to keep each function small enough to fit in a single editor window. This principle was followed in developing the byte code compiler and resulted in a system of approximately 450 functions. If this system is to coexist with another system of similar size it is essential to be able to prevent accidental name clashes--some form of name space management is needed. Common Lisp uses packages for name space management, and the package mechanism has been added to XLISP.

The following example shows a simple file using the package mechanism.

(defpackage "MYPACKAGE" (:use "CL"))
(in-package "MYPACKAGE")

(export '(h k))
(defun g (x) (+ x 1))
(defun h (x) (+ (g x) 2))
(defun k (x) (h x))
Within the package all local symbols are available: h and k both use the unexported function g. To use the exported symbols outside mypackage either you need to import the symbols into your package, or you can refer to them by prefixing their names with the package name and a colon:
> (mypackage:h 1)
4
Since g is not exported it cannot be accessed in this way:
> (mypackage:g 1)
Error: external symbol not found - "G"
However Lisp philosophy is to not close off access to any internals unless doing so would allow significant performance improvements; therefore it is possible to access an internal symbol using a double colon:
> (mypackage::g 1)
2
Thus the package mechanism does not prevent access to internal symbols but it does prevent inadvertent access.


next up previous
Next: Random Number Generators Up: Additions Since First Release Previous: Byte Code Compiler
Luke Tierney
5/27/1998