Re: requiring a library?

From: Pascal Bourguignon (spam_at_thalassa.informatimago.com)
Date: 02/02/04


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/


Relevant Pages

  • packages, load paths and environment variables
    ... so far I have been experimenting around with using packages the correct ... is the (LOAD "foo") in 'bar.lisp'. ... lisp session. ... I want to avoid giving absolute path names. ...
    (comp.lang.lisp)
  • BULK Processing Process "Expires" without completing
    ... I'm going to have more tables to load - I don't want to do what the current ... Is it possible that somehow I'm running out of memory and not completely ... I should also point out that up to now nobody has tried to write packages ... against this database and I'm not completely sure the database is configured ...
    (comp.databases.oracle.server)
  • Re: [SLE] Creating an FTP site for installing packages
    ... > I have SuSE Linux 9.2 Professional on CD and DVD. ... > Solaris box, and then get YAST to load packages from there, rather than ... > FTP server. ...
    (SuSE)
  • Re: Captain Jakes Top Ten List of what Id like to see inthenextversionofDelphi
    ... Understood, but in Delphi 7, for me, it doesn't work. ... packages that can be checked/unchecked for each project. ... load the project up and have all the packages load as well. ... You have to install them separately. ...
    (borland.public.delphi.non-technical)
  • Re: package management
    ... Currently on my machines live the following types of packages: ... contains all of the Lisp libraries I use and I ... I don't use ASDF-INSTALL, and on my Debian ...
    (comp.lang.lisp)