Next: , Up: Package Locks   [Contents][Index]


2.5.1 Rationale

Package locks are an aid to program development, by helping to detect inadvertent name collisions and function redefinitions. They are consistent with the principle that a package “belongs to” its implementor, and that noone other than the package’s developer should be making or modifying definitions on symbols in that package. Package locks are compatible with the ANSI Common Lisp standard, which states that the consequences of redefining functions in the COMMON-LISP package are undefined.

Violation of a package lock leads to a continuable error of type lisp::package-locked-error being signaled. The user may choose to ignore the lock and proceed, or to abort the computation. Two other restarts are available, one which disables all locks on all packages, and one to disable only the package-lock or package-definition-lock that was tripped.

The following transcript illustrates the behaviour seen when attempting to redefine a standard macro in the COMMON-LISP package, or to redefine a function in one of CMUCL’s implementation-defined packages:

CL-USER> (defmacro 1+ (x) (* x 2))
Attempt to modify the locked package COMMON-LISP, by defining macro 1+
   [Condition of type LISP::PACKAGE-LOCKED-ERROR]

Restarts:
  0: [continue      ] Ignore the lock and continue
  1: [unlock-package] Disable the package's definition-lock then continue
  2: [unlock-all    ] Unlock all packages, then continue
  3: [abort         ] Return to Top-Level.

CL-USER> (defun ext:gc () t)
Attempt to modify the locked package EXTENSIONS, by redefining function GC
   [Condition of type LISP::PACKAGE-LOCKED-ERROR]

Restarts:
  0: [continue      ] Ignore the lock and continue
  1: [unlock-package] Disable package's definition-lock, then continue
  2: [unlock-all    ] Disable all package locks, then continue
  3: [abort         ] Return to Top-Level.

The following transcript illustrates the behaviour seen when an attempt to modify the structure of a package is made:

CL-USER> (unexport 'load-foreign :ext)
Attempt to modify the locked package EXTENSIONS, by unexporting symbols LOAD-FOREIGN
   [Condition of type lisp::package-locked-error]

Restarts:
  0: [continue      ] Ignore the lock and continue
  1: [unlock-package] Disable package's lock then continue
  2: [unlock-all    ] Unlock all packages, then continue
  3: [abort         ] Return to Top-Level.

The COMMON-LISP package and the CMUCL-specific implementation packages are locked on startup. Users can lock their own packages by using the ext:package-lock and ext:package-definition-lock accessors.


Next: , Up: Package Locks   [Contents][Index]