Suppose I have two packages, say A and B. I'd like to define new
package, say C with all symbols from A and C being accessible in
it. The difficulty is the following. A and B have few symbols with the
same name. For each of them I know which one should be used. The whole
number of the exported symbols make it rather inconvenient to enumerate
them explicitly. Could you suggest something ? Preferably if it will
be DEFPACKAGE form.
--
Vladimir Zolotykh
Vladimir Zolotykh <······@eurocom.od.ua> writes:
> Suppose I have two packages, say A and B. I'd like to define new
> package, say C with all symbols from A and C being accessible in
> it. The difficulty is the following. A and B have few symbols with the
> same name. For each of them I know which one should be used. The whole
> number of the exported symbols make it rather inconvenient to enumerate
> them explicitly. Could you suggest something ? Preferably if it will
> be DEFPACKAGE form.
The third package (not calling it C because CMUCL has that
already) can shadowing-import the few conflicting symbols from
the correct packages. Having done this, it can use A and B
without name clashes and thus get the rest of the symbols without
listing them one by one.
* (defpackage "A"
(:use)
(:export "FOO" "BAR" "AIRPLANE" "MOTORCYCLE" "TRAIN"))
#<The A package, 0/4 internal, 5/5 external>
* (defpackage "B"
(:use)
(:export "FOO" "BAR" "CENTAUR" "GNOME" "MARILITH"))
#<The B package, 0/4 internal, 5/5 external>
* (defpackage "BOTH"
(:use "A" "B")
(:shadowing-import-from "A" "FOO")
(:shadowing-import-from "B" "BAR"))
#<The BOTH package, 2/9 internal, 0/2 external>
* 'both::foo
A:FOO
* 'both::bar
B:BAR
* 'both::gnome
B:GNOME
* 'both::train
A:TRAIN
(Could you explain the subject of this thread? It looked like
you would have a case-sensitivity question.)
Sorry for rather delayed reaction, I had to pay my attention
to other pressing matter...
> * (defpackage "BOTH"
> (:use "A" "B")
> (:shadowing-import-from "A" "FOO")
> (:shadowing-import-from "B" "BAR"))
From this I could conclude that DEFPACKAGE does some clever
things with its clauses. At least it can't simply do USE-PACKAGE twice
for example....
> * 'both::train
> A:TRAIN
Useful technique, previously I used FIND-SYMBOL, but
this one seems more convenient.
>
> (Could you explain the subject of this thread? It looked like
> you would have a case-sensitivity question.)
Something like 'The case of DEFPACKAGE study' I meant.
--
Vladimir Zolotykh
Vladimir Zolotykh <······@eurocom.od.ua> writes:
> > * (defpackage "BOTH"
> > (:use "A" "B")
> > (:shadowing-import-from "A" "FOO")
> > (:shadowing-import-from "B" "BAR"))
>
> From this I could conclude that DEFPACKAGE does some clever
> things with its clauses. At least it can't simply do USE-PACKAGE twice
> for example....
DEFPACKAGE reorders the clauses so that :shadowing-import-from
comes first. This is explained in CLHS. You can do the same
thing yourself:
* (defpackage "A"
(:use)
(:export "FOO" "BAR" "AIRPLANE" "MOTORCYCLE" "TRAIN"))
#<The A package, 0/4 internal, 5/5 external>
* (defpackage "B"
(:use)
(:export "FOO" "BAR" "CENTAUR" "GNOME" "MARILITH"))
#<The B package, 0/4 internal, 5/5 external>
* ;; Note I do not use DEFPACKAGE here.
(make-package "BOTH" :use '())
#<The BOTH package, 0/9 internal, 0/9 external>
* (in-package "BOTH")
#<The BOTH package, 0/9 internal, 0/9 external>
* (cl:shadowing-import 'a:foo)
COMMON-LISP:T
* (cl:shadowing-import 'b:bar)
COMMON-LISP:T
* (cl:use-package "A")
COMMON-LISP:T
* (cl:use-package "B")
COMMON-LISP:T
*
> > * 'both::train
> > A:TRAIN
>
> Useful technique, previously I used FIND-SYMBOL, but
> this one seems more convenient.
This is more like INTERN. You can get unwanted symbols.