Re: requiring a library?
From: Pascal Bourguignon (spam_at_thalassa.informatimago.com)
Date: 02/02/04
- Next message: Joe Marshall: "Re: Understanding #' and function variables"
- Previous message: Erann Gat: "Re: Understanding #' and function variables"
- In reply to: Oliver Scholz: "requiring a library?"
- Next in thread: Christophe Rhodes: "Re: requiring a library?"
- Reply: Christophe Rhodes: "Re: requiring a library?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 02 Feb 2004 20:26:37 +0100
Oliver Scholz <alkibiades@gmx.de> writes:
> I am new to CL and I am still in the process of setting up a working
> environment (on GNU/Linux with SBCL and Smile).
>
> To my surprise I read in the Hyperspec:
>
> The functions provide and require are deprecated.
>
> So how am I supposed to require a lisp library? My expectation was
> that I set up the load-path (whatever the equivalent, if any, might
> be -- I have not investigated yet), install some lisp libaries that
> might be useful into the proper places and put an according
> `(require LIBRARY)' at the top of files on which I am working, if
> necessary.
>
> If this expectation is basically right, what functions am I supposed
> to use if `require' and `provide' are deprecated? If this expectation
> happens to be wrong, what is the typical way to use lisp libraries in
> lisp programs?
What I do:
- define a bunch of logical path name translations.
- use LOAD.
- for some complicated "libraries" that need special processing for
loading, I've got loaders lisp files.
For example:
(DEFMACRO SCONC (&REST ARGS) `(CONCATENATE 'STRING ,@ARGS))
(DEFMACRO DEF-LP-TRANS (HOST PATH &OPTIONAL SUBPATH)
(SETQ SUBPATH (OR SUBPATH ""))
`(SETF (LOGICAL-PATHNAME-TRANSLATIONS ,HOST)
(LIST
(LIST "**;*" (SCONC ,PATH ,SUBPATH "**/*"))
(LIST "**;*.*" (SCONC ,PATH ,SUBPATH "**/*.*"))
(LIST "**;*.*.*" (SCONC ,PATH ,SUBPATH "**/*.*.*"))
)));;DEF-LP-TRANS
(DEFCONSTANT +SHARE-LISP+ "/local/share/lisp/")
(DEF-LP-TRANS "CMU-AI" +SHARE-LISP+ "ai/")
(DEF-LP-TRANS "CLOCC" +SHARE-LISP+ "clocc/")
(DEF-LP-TRANS "CL-PDF" +SHARE-LISP+ "cl-pdf/")
(DEF-LP-TRANS "PSEUDO" +SHARE-LISP+ "pseudo/")
(DEF-LP-TRANS "CCLAN" +SHARE-LISP+ "cclan/")
;; Use (LOAD "LOADER:CCLAN.LISP") to load cclan.
(DEF-LP-TRANS "UFFI" +SHARE-LISP+ "uffi-1.2.15/")
;; Use (LOAD "LOADER:UFFI.LISP") to load uffi
(DEFCONSTANT +PJB-COMM+ "/home/pascal/src/common/")
(DEFCONSTANT +PJB-LISP+ "/home/pascal/src/lisp/")
(DEF-LP-TRANS "HOME" "/home/pascal/" "")
(DEF-LP-TRANS "LOADER" +PJB-LISP+ "loaders/")
(DEF-LP-TRANS "NORVIG" +PJB-LISP+ "norvig/")
In addition, I manage my packages with a mapping between the package
name and a logical pathname translation in logical host "PACKAGES":
(COM.INFORMATIMAGO.COMMON-LISP.PACKAGE:ADD-TRANSLATIONS
(LIST "**;*" (SCONC +SHARE-LISP+ "packages/**/*"))
(LIST "**;*.*" (SCONC +SHARE-LISP+ "packages/**/*.*"))
(LIST "**;*.*.*" (SCONC +SHARE-LISP+ "packages/**/*.*.*"))
)
Then:
(COM.INFORMATIMAGO.COMMON-LISP.PACKAGE:LOAD-PACKAGE
"COM.INFORMATIMAGO.COMMON-LISP.POSIX.ED")
(COM.INFORMATIMAGO.COMMON-LISP.POSIX.ED:ED)
Or I load directly a file:
(LOAD "PACKAGES:NET;SOURCEFORGE;GARNET;RUNDEMO.LISP")
Perhaps you're asking, for from the source of a package. Here I've
have a DEFINE-PACKAGE macro that encapsulate DEFPACKAGE, IN-PACKAGE,
and LOAD:
;; (DEFINE-PACKAGE COM.INFORMATIMAGO.COMMON-LISP.EXAMPLE
;; (:NICKNAMES NAME1 NAM2) ; use (:USE pack :AS nick) in client rather!
;; (:DOCUMENTATION "BLAH BLAH")
;; (:USE COMMON-LISP)
;; (:FROM COM.INFORMATIMAGO.COMMON-LISP.LIST :IMPORT :ALL)
;; (:FROM COM.INFORMATIMAGO.COMMON-LISP.STRING :IMPORT SYM1 SYM2 SYM3)
;; (:USE COM.INFORMATIMAGO.COMMON-LISP.UTILITY :AS UTIL)
;; (:USE COM.INFORMATIMAGO.COMMON-LISP.DICTIONARY)
;; (:EXPORT EXP1 EXP2 EXP3))
- Symbols are converted to string early,
- Nicknames are not generally specified in the DEFINE-PACKAGE, but
when the package is loaded (:USE clause). (There's still a problem
with current implementation in that two clients using the same
nickname for a different package collide)
- Note how the example DEFINE-PACKAGE documents the use of the
COM.INFORMATIMAGO.COMMON-LISP.DICTIONARY package. in 99% of the
packages, this could be known only by parsing the whole package
sources. Granted, in perhaps 1% of the packages, they will try to
use dynamically other packages, not know at compilation time. But
for normal packages, this :USE declaration (along with the other
:FROM declarations) allow to build a dependency graph (makefile) and
to load automatically the needed packages (defsystem), all at once.
-- __Pascal_Bourguignon__ http://www.informatimago.com/ There is no worse tyranny than to force a man to pay for what he doesn't want merely because you think it would be good for him.--Robert Heinlein http://www.theadvocates.org/
- Next message: Joe Marshall: "Re: Understanding #' and function variables"
- Previous message: Erann Gat: "Re: Understanding #' and function variables"
- In reply to: Oliver Scholz: "requiring a library?"
- Next in thread: Christophe Rhodes: "Re: requiring a library?"
- Reply: Christophe Rhodes: "Re: requiring a library?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|