
7.3.4 Using packages in interpreted and compiled code
Note that the double-colon qualification syntax means one of two things:
export oruse-package operation, 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)))
ace package--is either directly inherited from the very stablelisp package or is directly present in theace package. The call toimport cannot spuriously create any symbols in theuser package. On the other hand, the formatuser::string-width can make additions to theuser package that violate the assumptions made in previously compiled files. If you are using the Window Tool Kit, theuser package will inherit the symbolstring-width from thewindows package. If you are using an image that does not contain the Window Tool Kit, you do not have awindows 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 requisiteuse-package links are established, irreparable damage can occur.

Generated with Harlequin WebMaker