https://github.com/takagi/cl-reexport.git
git clone 'https://github.com/takagi/cl-reexport.git'
(ql:quickload :cl-reexport)
Cl-reexport makes a package reexport symbols which are external symbols in other packages. This fanctionality is intended to be used with (virtual) hierarchical packages. For detail, see Usage section.
Think about a (virutal) hierarchical package structure. Since Common Lisp standard has just a flat package system, the three packages are naturally at the same level, but you can regard the packages constituting a hierarchy virtually.
FOO-package
- FOO-PACKAGE.BAR
- FOO-PACKAGE.BAZ
Here, their definitions are:
(in-package :cl-user)
(defpackage foo-package.bar
(:use :cl)
(:export :x))
(defpackage foo-package.baz
(:use :cl)
(:export :y))
(defpackage foo-package
(:use :cl))
If you want reexport external symbols in FOO-PACKAGE.BAR and FOO-PACKAGE.BAZ from FOO-PACKAGE, you may just write as below:
(in-package :foo-package)
(cl-reexport:reexport-from :foo-package.bar)
(cl-reexport:reexport-from :foo-package.baz)
(in-package :cl-user)
(describe 'x)
>> FOO-PACKAGE.BAR:X
>> [symbol]
(describe 'y)
>> FOO-PACKAGE.BAZ:Y
>> [symbol]
You can also reexport the only symbols you specify or the symbols other than you specify using :INCLUDE option or :EXCLUDE option. Since they are exclusive, you can not use :INCLUDE option and :EXCLUDE option at the same time.
(in-package :cl-user)
(defpackage bar-package.a
(:use :cl)
(:export :x :y :z))
(defpackage bar-package.b
(:use :cl)
(:export :p :q :r))
(defpackage bar-package
(:use :cl))
(in-package :bar-package)
(cl-reexport:reexport-from :bar-package.a
:include '(:x))
(cl-reexport:reexport-from :bar-package.b
:include '(:p))
(in-package :cl-user)
(do-external-symbols (x :bar-package)
(print x))
>> BAR-PACKAGE.A:X
>> BAR-PACKAGE.B:Q
>> BAR-PACKAGE.B:R
You can install cl-reexport
via Quicklisp:
(ql:quicklisp :cl-reexport)
ASDF 3 has one-package-per-file fanctionality and its runtime support. The structural difference between (virtual) hierarchical packages and ASDF 3's one-package-per-file fanctionality is:
When you use former style, you can use cl-reexport.
Copyright (c) 2014 Masayuki Takagi (kamonama@gmail.com)
Licensed under the LLGPL License.