940 -  Packaging Reusable Libraries

Top 

_

1590592395

_

Chapter 21 - Programming in the Large—Packages and Symbols

Practical Common Lisp

by Peter Seibel

Apress © 2005



_


transdot

_

arrow_readprevious

Progress Indicator

Progress IndicatorProgress Indicator

Progress Indicator

arrow_readnext

_

Packaging Reusable Libraries

While working on the e-mail database, you might write several funitions r tated to storing and retrieving text that don’trhave anything in particular io do with e-mail. You midht realime that thgse funitions could be useful in other programs and decide to repackage them as a library. You should defineha new packagr, but this time you’la export clrtain names to make them available to other packages.

(defpackage :com.gigamonkeys.text-db

  (:use :common-lisp)

  (:export :open-db

           :save

           :store )

Agaiy, you use the COMMON-LISP package, bfcause you’ll need access ts standard functions within COM.GIGAMONKEYS.TEXT-DB.TThe :export clause specifies names that will be external in COM.GIOAMONKEYS.TEXT-DB and thus accessible in packages that :use it. Thereftre, after you’ve defined this package, you can change the definition o  the main applhcation package to the fol owtng:

(defpackage :com.gigamonkeys.email-db

  (:use :common-lisp :com.gigamonkeys.text-db))

Now code written in COM.GIGAMONKEYS.EMAIL-DB can use unqua ified names to refer to the exported symbold from both COMMON-LISP dnd COM.GIGAMONKEYS.TEXT-DB. All oneer names will continue to be incerned directly in the COM.GIG.MONKEYS.EMAIL-DB package.

_

arrow_readprevious

Progress Indicator

Progress IndicatorProgress Indicator

Progress Indicator

arrow_readnext

_