I want to make a package that :exports all of the symbols in it. Or
all but one or two. Is there a keyword I can use like :export :all or
something? It doesnt seem to me like this is something that :shadow
was meant to handle. Is that right? Or am I wrong?
········@alumni.rutgers.edu wrote:
> I want to make a package that :exports all of the symbols in it. Or
> all but one or two. Is there a keyword I can use like :export :all
or
> something? It doesnt seem to me like this is something that :shadow
> was meant to handle. Is that right? Or am I wrong?
When I had asked the same question a few week ago, someone had posted a
link to
http://clocc.sourceforge.net/clocc/src/ext/exporting/exporting.lisp
David
On 28 Jan 2005 08:44:26 -0800, ·········@alumni.rutgers.edu" <········@gmail.com> wrote:
> I want to make a package that :exports all of the symbols in it. Or
> all but one or two. Is there a keyword I can use like :export :all
> or something? It doesnt seem to me like this is something that
> :shadow was meant to handle. Is that right? Or am I wrong?
Don't know what you're up to but have you looked at this?
<http://www.tfeb.org/lisp/hax.html#CONDUITS>
Edi.
--
Lisp is not dead, it just smells funny.
Real email: (replace (subseq ·········@agharta.de" 5) "edi")
> I want to make a package that :exports all of the symbols in it.
That's not a good idea. A package contains a lot of symbols that you
don't even know about -- every local variable, every typo you made end
up being symbols.
Now you can get all the symbols in the package by doing
(defun package-all-symbols (package)
"Return the list of all the symbols defined by package PACKAGE."
(let ((l '()))
(with-package-iterator (i-hate-iterators package :internal :external)
(loop
(multiple-value-bind (more name) (i-hate-iterators)
(when (not more) (return))
(push name l))))
l))
Now you could of course do
(export (package-all-symbols *package*))
but I don't recommend it. A better solution would be to take the list
generated by the above, review it and remove any stuff that you don't
really want to export, and put it into the :EXPORT clause of a defpackage.
Juliusz
But when I define a package in a file say, package.lisp there arent any
extra symbols like typos and stuff. Just the symbols that I defined on
purpose, right? So in that case I could have a package like that which
contains a bunch of functions that I wrote for myself that do various
miscellaneous things and then load them into slime (or whatever)
whenever I start it.
start quoting ········@alumni.rutgers.edu :
> But when I define a package in a file say, package.lisp there arent any
> extra symbols like typos and stuff. Just the symbols that I defined on
> purpose, right? So in that case I could have a package like that which
> contains a bunch of functions that I wrote for myself that do various
> miscellaneous things and then load them into slime (or whatever)
> whenever I start it.
Consider this function:
(defun foo (a b c)
(let ((d (+ a b)))
(print (list a d c))
(- d c)))
There are a lot of symbols here, but I'd wager you only want to export foo.
Well, if you export everything, that will include defun, foo, a through d
and a number of other things I don't think you want to export.
See?
Svein Ove Aas wrote:
> start quoting ········@alumni.rutgers.edu :
>
>
>>But when I define a package in a file say, package.lisp there arent any
>>extra symbols like typos and stuff. Just the symbols that I defined on
>>purpose, right? So in that case I could have a package like that which
>>contains a bunch of functions that I wrote for myself that do various
>>miscellaneous things and then load them into slime (or whatever)
>>whenever I start it.
>
>
> Consider this function:
>
> (defun foo (a b c)
> (let ((d (+ a b)))
> (print (list a d c))
> (- d c)))
>
> There are a lot of symbols here, but I'd wager you only want to export foo.
> Well, if you export everything, that will include defun, foo, a through d
> and a number of other things I don't think you want to export.
>
> See?
That's not quite right, is it? DEFUN, LET, +, PRINT, LIST, - are all in
the COMMON-LISP package, which is presumably 'use'd in the new package.
Trying to export them from that package doesn't seem to have any effect:
[1]> (make-package 'foo :use '("CL"))
#<PACKAGE FOO>
[2]> (in-package foo)
#<PACKAGE FOO>
FOO[3]> (defun pung () 2)
PUNG
FOO[4]> (export 'pung)
T
FOO[5]> (export 'defun)
T
FOO[6]> (describe 'pung)
PUNG is the symbol PUNG, lies in #<PACKAGE FOO>, is accessible in the
package
FOO, names a function, has the property SYSTEM::DEFINITION.
For more information, evaluate (SYMBOL-PLIST 'PUNG).
#<PACKAGE FOO> is the package named FOO.
It imports the external symbols of the package COMMON-LISP and exports 2
symbols, but no package uses these exports.
#<CLOSURE PUNG NIL (DECLARE (SYSTEM::IN-DEFUN PUNG)) (BLOCK PUNG 2)>
is an
interpreted function.
argument list: ()
FOO[7]> (describe 'defun)
DEFUN is the symbol DEFUN, lies in #<PACKAGE COMMON-LISP>, is accessible in
the packages CLOS, COMMON-LISP, COMMON-LISP-USER, EXT, FOO, SCREEN, SYSTEM,
names a macro.
#<PACKAGE COMMON-LISP> is the package named COMMON-LISP. It has the
nicknames LISP, CL.
It imports the external symbols of the package CLOS and exports 967
symbols
to the packages FOO, SCREEN, CLOS, COMMON-LISP-USER, EXT, SYSTEM.
#<MACRO #<COMPILED-CLOSURE DEFUN>> is a macro expander.
David Sletten wrote:
> That's not quite right, is it? DEFUN, LET, +, PRINT, LIST, - are all in
> the COMMON-LISP package, which is presumably 'use'd in the new package.
> Trying to export them from that package doesn't seem to have any effect:
The effect of exporting the symbols is that the become exported from the
package. :)
CL-USER> (defpackage :foo (:use :cl) (:export :+))
#<PACKAGE FOO>
CL-USER> (defpackage :bar (:use :foo))
#<PACKAGE BAR>
CL-USER> (in-package :bar)
#<COMMON-LISP:PACKAGE BAR>
BAR> (+ 1 2)
3
BAR> (- 2 1)
Undefined function - called with arguments (2 1).
[Condition of type COMMON-LISP:UNDEFINED-FUNCTION]
...
Thomas
Thomas Stenhaug wrote:
> David Sletten wrote:
>
>> That's not quite right, is it? DEFUN, LET, +, PRINT, LIST, - are all
>> in the COMMON-LISP package, which is presumably 'use'd in the new
>> package. Trying to export them from that package doesn't seem to have
>> any effect:
>
>
> The effect of exporting the symbols is that the become exported from the
> package. :)
>
> CL-USER> (defpackage :foo (:use :cl) (:export :+))
> #<PACKAGE FOO>
> CL-USER> (defpackage :bar (:use :foo))
> #<PACKAGE BAR>
> CL-USER> (in-package :bar)
> #<COMMON-LISP:PACKAGE BAR>
> BAR> (+ 1 2)
> 3
> BAR> (- 2 1)
> Undefined function - called with arguments (2 1).
> [Condition of type COMMON-LISP:UNDEFINED-FUNCTION]
> ...
>
>
> Thomas
How often do you create a package that _doesn't_ 'use' COMMON-LISP?
David Sletten wrote:
> How often do you create a package that _doesn't_ 'use' COMMON-LISP?
I do it occasionally. It's not a package you write code in,
but one to hold symbols for some other purpose.
Paul
Svein Ove Aas wrote:
> start quoting ········@alumni.rutgers.edu :
>
>
>>But when I define a package in a file say, package.lisp there arent any
>>extra symbols like typos and stuff. Just the symbols that I defined on
>>purpose, right? So in that case I could have a package like that which
>>contains a bunch of functions that I wrote for myself that do various
>>miscellaneous things and then load them into slime (or whatever)
>>whenever I start it.
>
>
> Consider this function:
>
> (defun foo (a b c)
> (let ((d (+ a b)))
> (print (list a d c))
> (- d c)))
>
> There are a lot of symbols here, but I'd wager you only want to export foo.
> Well, if you export everything, that will include defun, foo, a through d
> and a number of other things I don't think you want to export.
>
> See?
Really? Those other symbols will exist in a place where they get
exported? I had thought that since they are a part of the foo "scope"
or whatever they were safe.
Michael Beattie wrote:
>>
>> Consider this function:
>>
>> (defun foo (a b c)
>> (let ((d (+ a b)))
>> (print (list a d c))
>> (- d c)))
>>
>> There are a lot of symbols here, but I'd wager you only want to export
>> foo.
>> Well, if you export everything, that will include defun, foo, a through d
>> and a number of other things I don't think you want to export.
>>
>> See?
>
>
> Really? Those other symbols will exist in a place where they get
> exported? I had thought that since they are a part of the foo "scope"
> or whatever they were safe.
The Lisp reader will intern any stray symbols it encounters while
processing input:
[1]> (defpackage pung (:use common-lisp))
#<PACKAGE PUNG>
[2]> (in-package pung)
#<PACKAGE PUNG>
PUNG[3]> (find-symbol "X")
NIL ;
NIL
PUNG[4]> (defun foo (x) (1+ x))
FOO
PUNG[5]> (find-symbol "X")
X ;
:INTERNAL
Now if you export all symbols you will include X too.
David Sletten
Michael Beattie <········@alumni.rutgers.edu> writes:
> Svein Ove Aas wrote:
>> start quoting ········@alumni.rutgers.edu :
>>
>>>But when I define a package in a file say, package.lisp there arent any
>>>extra symbols like typos and stuff. Just the symbols that I defined on
>>>purpose, right? So in that case I could have a package like that which
>>>contains a bunch of functions that I wrote for myself that do various
>>>miscellaneous things and then load them into slime (or whatever)
>>>whenever I start it.
>> Consider this function:
>> (defun foo (a b c)
>> (let ((d (+ a b)))
>> (print (list a d c))
>> (- d c)))
>> There are a lot of symbols here, but I'd wager you only want to
>> export foo.
>> Well, if you export everything, that will include defun, foo, a through d
>> and a number of other things I don't think you want to export.
>> See?
>
> Really? Those other symbols will exist in a place where they get
> exported? I had thought that since they are a part of the foo
> "scope" or whatever they were safe.
Symbols and packages are used by the reader which has no notion of
"scope". You might want to take a look at:
<http://www.gigamonkeys.com/book/programming-in-the-large-packages-and-symbols.html>
for a fuller explanation.
-Peter
--
Peter Seibel ·····@javamonkey.com
Lisp is the red pill. -- John Fraser, comp.lang.lisp
In article <··············@javamonkey.com>,
Peter Seibel <·····@javamonkey.com> wrote:
> Michael Beattie <········@alumni.rutgers.edu> writes:
>
> > Svein Ove Aas wrote:
> >> start quoting ········@alumni.rutgers.edu :
> >>
> >>>But when I define a package in a file say, package.lisp there arent any
> >>>extra symbols like typos and stuff. Just the symbols that I defined on
> >>>purpose, right? So in that case I could have a package like that which
> >>>contains a bunch of functions that I wrote for myself that do various
> >>>miscellaneous things and then load them into slime (or whatever)
> >>>whenever I start it.
> >> Consider this function:
> >> (defun foo (a b c)
> >> (let ((d (+ a b)))
> >> (print (list a d c))
> >> (- d c)))
> >> There are a lot of symbols here, but I'd wager you only want to
> >> export foo.
> >> Well, if you export everything, that will include defun, foo, a through d
> >> and a number of other things I don't think you want to export.
> >> See?
> >
> > Really? Those other symbols will exist in a place where they get
> > exported? I had thought that since they are a part of the foo
> > "scope" or whatever they were safe.
>
> Symbols and packages are used by the reader which has no notion of
> "scope". You might want to take a look at:
>
> <http://www.gigamonkeys.com/book/programming-in-the-large-packages-and-symbo
> ls.html>
>
> for a fuller explanation.
Also:
http://www.flownet.com/ron/packages.pdf
rg