[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
OK, so I have a package reference in my init file...
Date: Mon, 4 Jun 90 21:15 EDT
From: pan@Athena.Pangaro.Dialnet.Symbolics.Com (Paul Pangaro)
... but the world I load might not have that package defined (either
yet, or will never at all). How can I put a reference to the package in
my init, but with a test so I dont crash on undefined package for the
worlds where that aint loaded. (Using package bind does not help but I'm
not sure why that crashes too, even though I no longer have a form like
Am I thinking about this correctly? Thanks.
There are two possible techniques. The one which is `intended' (and I use the
word loosely since I doubt anyone gave serious thought to this particular
quandry in its design) by CLtL is for you to put the stray package references
in another file and then conditionally load the other file based on whether
the appropriate packages and/or systems are loaded.
However, this is really tedious for init files which typically violate modularity
in order to set up all kinds of options.
(Of course, there's always #+ and #-, too, but that only works in situations where
there is a feature name to go along with the package in question.)
>From my init file...
(DEFUN INIT-KMP (...)
(FLET ((IF-PACKAGE (PKG STRING)
(IF (FIND-PACKAGE PKG) (EVAL (READ-FROM-STRING STRING)))))
"(WHEN (IGNORE-ERRORS (TYPEP TV:DEFAULT-SCREEN 'COLOR:CAD-BUFFER-OVERLAY-MIXIN))
(SEND TV:DEFAULT-SCREEN :SET-BOW-MODE NIL)
(SEND TV:DEFAULT-SCREEN :SET-BACKGROUND-COLOR '(0.15 0.35 1.00))
(SEND TV:DEFAULT-SCREEN :SET-FOREGROUND-COLOR '(1.00 1.00 1.00)))")
"(WHEN (FBOUNDP 'STOCK::MONITOR-STOCK-IN-BACKGROUND)
(STOCK::MONITOR-STOCK-IN-BACKGROUND T '(:SMBX)))")
I wouldn't say it's the absolute most graceful thing you could do (especially since you
have to hand-indent things because Tab doesn't work so well inside string-quotes)
... but it does get the job done.
This technique (especially putting it in a DEFUN) has the advantage that if
you later load support (e.g., for COLOR or STOCK in the example above), then you
can re-run the DEFUN and it will not have gotten rid of the code it needs in the
same way as a #+ or #- might have.