(Examples and some text from book Practical Common Lisp)
If you have experiment on C++ or C# language , you must be familiar with the name space which is used to resolve the name conflict in a large project. In C++, we use the
To read code in one package, you need to make it the current package with the IN-PACKAGE macro.
(in-package :yourpackage)
If you type this in the REPL. it will change the value of the *package*, affecting how the REPL reads subsequent expressions.
Packaging Reusable Libraries
If you are using the COMMON-LISP package, because you’ll need access to standard functions within COM.GIGAMONKEYS.TEXT-DB. The :export clause specifies names that will be external in COM.GIGAMONKEYS.TEXT-DB and thus accessible in packages that :use it.
(defpackage :com.gigamonkeys.email-db
(:use :common-lisp :com.gigamonkeys.text-db))
If you only want to use a function in other package, but others names have the conflict with the current package you are using. You can only import the specify function from other package.
(defpackage :com.gigamonkeys.email-db
(:use :common-lisp :com.gigamonkeys.text-db)
(:import-from :com.acme.email :parse-email-address))
Occasionally you’ll run into the opposite situation—a package may export a bunch of names you want to use and a few you don’t. Rather than listing all the symbols you do want to use in an :import-from clause, you can instead :use the package and then list the names you don’t want to inherit in a :shadow clause.
You can use the :nicknames to give the package a nickname, like the Common-Lisp whose nickname is CL-USER. If you want to give some documentation to the package, you can use the :documentation.
No comments:
Post a Comment