7.3.4 Using packages in interpreted and compiled code
Note that the double-colon qualification syntax means one of two things:
use-packageoperation, it is typically too late to correct the error.
Occasionally, it is preferable to import the desired symbol into the package where it will be used, rather than altering the exterior interface of the package in which it resides. Compare these two examples:
;;; File 1 looks like this. ;;; -*- Mode: LISP; Syntax: Common-Lisp; Package: ACE; ;;; Base: 10 -*- (in-package "ACE") (defun how-wide (x) (check-type x string) (+ (user::string-width x) (user::string-width y)))The first file has a much higher potential for compile-time/load-time conflicts than the second file. The second file is more secure because every symbol in the main contents of the file--the part not concerned with creating the
;;; File 2 looks like this. ;;; -*- Mode: Lisp; Syntax: Common-Lisp; Package: ACE; ;;; Base: 10 -*- (in-package "ACE") (import (or (find-symbol "STRING-WIDTH" "USER") (error "STRING-WIDTH missing from the USER package"))) (defun how-wide (x y) (check-type x string) (+ (string-width x) (string-width y)))
acepackage--is either directly inherited from the very stable
lisppackage or is directly present in the
acepackage. The call to
importcannot spuriously create any symbols in the
userpackage. On the other hand, the format
user::string-widthcan make additions to the
userpackage that violate the assumptions made in previously compiled files.
If you are using the Window Tool Kit, the
user package will inherit the symbol
string-width from the
windows package. If you are using an image that does not contain the Window Tool Kit, you do not have a
windows package to inherit from; thus, if you read in this example file, subsequent attempts to load in the Window Tool Kit will break with irreconcilable name conflicts. This problem is symptomatic of any situation in which modules or packages are separately compiled and dynamically loaded. If you use the double-colon format on a package before all of its externals are defined or before all of its requisite
use-package links are established, irreparable damage can occur.
Generated with Harlequin WebMaker