From: Tamas
Subject: "reexporting" symbols
Date: 
Message-ID: <10ef1e27-1274-462e-b964-c97126e7fce1@d21g2000prf.googlegroups.com>
Hi,

Sorry for the inane subject line :-)  My problem is the following:  I
have package A which exports certain symbols:

(defpackage :a
  (:use :common-lisp)
  (:export foo bar))

and package B which uses package A's symbols, its defpackage looks
like

(defpackage :b
  (:use :common-lisp :a)
  (:export baz))

Both use ASDF, but I am not including their .asd files, they look
analogous.  Now the user loads B:

(in-package :cl-user)
(require :b)
(use-package '(:b))

But to take advantage of the full functionality of :b, symbols (for
functions) in :a need to be used.  I would like those symbols to be
automatically available whenever the symbols from :b are (eg
equivalent to writing

(use-package '(:b :a))

but only with :b).  Is this possible?

Thanks,

Tamas

From: jayessay
Subject: Re: "reexporting" symbols
Date: 
Message-ID: <m3odb9n11p.fsf@sirius.goldenthreadtech.com>
Tamas <······@gmail.com> writes:

> (defpackage :a
>   (:use :common-lisp)
>   (:export foo bar))
> 
> and package B which uses package A's symbols, its defpackage looks
> like
> 
> (defpackage :b
>   (:use :common-lisp :a)
>   (:export baz))
> 
...
> (in-package :cl-user)
> (require :b)
> (use-package '(:b))
> 
> But to take advantage of the full functionality of :b, symbols (for
> functions) in :a need to be used.  I would like those symbols to be
> automatically available whenever the symbols from :b are (eg
> equivalent to writing
> 
> (use-package '(:b :a))
> 
> but only with :b).  Is this possible?

Yes. You need to "reexport" the A symbols from B:

(in-package :b)
(do-external-symbols (s (find-package :a))
		     (export s))

or some such


/Jon

-- 
'j' - a n t h o n y at romeo/charley/november com
From: Peter Hildebrandt
Subject: Re: "reexporting" symbols
Date: 
Message-ID: <op.t5hy1ix9x6i8pv@babyfoot>
On Fri, 25 Jan 2008 17:45:15 +0100, Tamas <······@gmail.com> wrote:

> Hi,
>
> Sorry for the inane subject line :-)  My problem is the following:  I
> have package A which exports certain symbols:
>
> (defpackage :a
>   (:use :common-lisp)
>   (:export foo bar))
>
> and package B which uses package A's symbols, its defpackage looks
> like
>
> (defpackage :b
>   (:use :common-lisp :a)
>   (:export baz))
>
> Both use ASDF, but I am not including their .asd files, they look
> analogous.  Now the user loads B:
>
> (in-package :cl-user)
> (require :b)
> (use-package '(:b))
>
> But to take advantage of the full functionality of :b, symbols (for
> functions) in :a need to be used.  I would like those symbols to be
> automatically available whenever the symbols from :b are (eg
> equivalent to writing
>
> (use-package '(:b :a))
>
> but only with :b).  Is this possible?

Maybe I'm missing the obvious, but why not just export them when defining  
:b?

CL-USER> (defpackage :a
   (:use :common-lisp)
   (:export foo bar))
#<PACKAGE "A">
CL-USER> (defpackage :b
   (:use :common-lisp :a)
   (:export baz :foo :bar))   ;; <=======
#<PACKAGE "B">

And now:

CL-USER> (describe 'b:foo)
A:FOO is an external symbol in #<PACKAGE "A">.

and

CL-USER> (eq 'b:foo 'a:foo)
T

If you don't want to list all symbols manually in the defpackage, you  
might use the list of exported symbols of :a somewhere in :b and export  
them automatically.

Peter

> Thanks,
>
> Tamas



-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: Peter Hildebrandt
Subject: Re: "reexporting" symbols
Date: 
Message-ID: <op.t5hzgh0jx6i8pv@babyfoot>
On Fri, 25 Jan 2008 19:01:56 +0100, Peter Hildebrandt  
<·················@gmail.com> wrote:

> On Fri, 25 Jan 2008 17:45:15 +0100, Tamas <······@gmail.com> wrote:
>> But to take advantage of the full functionality of :b, symbols (for
>> functions) in :a need to be used.  I would like those symbols to be
>> automatically available whenever the symbols from :b are (eg
>> equivalent to writing
>>
>> (use-package '(:b :a))
>>
>> but only with :b).  Is this possible?
>
> If you don't want to list all symbols manually in the defpackage, you  
> might use the list of exported symbols of :a somewhere in :b and export  
> them automatically.

You could use (do-external-symbols ()):

(defpackage :a
   (:use :common-lisp)
   (:export foo bar))
#<PACKAGE "A">

CL-USER> (defpackage :b
   (:use :common-lisp :a)
   (:export baz))
#<PACKAGE "B">

CL-USER> (describe 'b:foo)
====> ERROR
; Evaluation aborted.

Put the following code somewhere in b.lisp, wrapped in (eval-when  
(:compile-toplevel :load-toplevel :execute) ...):

CL-USER> (do-external-symbols (sym :a)
	   (print (list 'exporting sym))
	   (export sym :b))

(EXPORTING A:BAR)
(EXPORTING A:FOO) NIL

And there you go:
CL-USER> (describe 'b:foo)

A:FOO is an external symbol in #<PACKAGE "A">.
; No value

Peter

----
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/