Re: package frenzy
- From: Peter Seibel <peter@xxxxxxxxxxxxxxx>
- Date: Mon, 30 May 2005 19:53:29 GMT
Joris Bleys <jorisb@xxxxxxxxxxxxxx> writes:
> Hi Peter,
>
>> For starters, presumably you're using READ not READ-LINE as the latter
>> returns a string, not a symbol. Or you're using READ-LINE and then
>> INTERN to create a symbol, which is arguably a better plan that using
>> READ so you don't have to worry about READ reading some other kind of
>> object.
>
> Actually I'm using (read-from-string "COMMAND extra stuff which ain't
> important" NIL NIL) which returns COMMAND as a symbol. I initially
> mispelled this as I thought this was not of major influence on my
> problem at hand).
>
>> At any rate, the problem you're having is that READ and INTERN
>> both use the runtime value of *PACKAGE* to determine how to
>> find/intern symbols. So it doesn't matter that ep-internal-fn happens
>> to be defined in a file that is read with a particular *PACKAGE*--what
>> matters is what *PACKAGE* is when it is called.
>
> Ok, I agree to you this indeed is the problem and the solution. I just
> find it a bit difficult for a programmer to make sure symbols are
> created in the right package. I wonder when calling an internal
> function, the *package* is not automatically changed to the package to
> the one in which it was defined.
So one nit-picky, but actually quite important point, is that's it
doesn't really make sense to talk of the package in which a function
was defined. For instance, in what package is this function defined:
(in-package :foo)
(defun bar::baz () 'hello)
The value of *PACKAGE* when this file is read will be the package
"FOO" but the name of the function BAZ will not be interned in
"FOO"[1]. So, in your dream Lisp, should *PACKAGE* be bound to the
package "FOO" or the package "BAR" when BAZ is called? That's a
rhetorical question--I'm sure you could come up with an answer and
maybe even make a case for why it makes more sense than the other
answer. But the fact of the matter is, that functions aren't "in"
packages--just their names. It's worth getting this straight in your
head because once you realize that packages are *just* a scheme for
managing names, and only indirectly the things they name, the package
system will make a lot more sense.
-Peter
[1] Well it could, if the "FOO" and "BAR" packages had the appropriate
relationships established. But leave that aside for the moment.
P.S. If you really want to define packages that rebind *PACKAGE* at
runtime to the package that was current when the function was defined,
you could define this macro:
(defmacro defun/package (name (&rest args) &body body)
`(defun ,name ,args
(let ((*package* ,*package*))
,@body)))
And if you want functions that bind *PACKAGE* to the HOME package of
the name of the function, you could define this one:
(defmacro defun/package (name (&rest args) &body body)
`(defun ,name ,args
(let ((*package* ,(symbol-package name)))
,@body)))
I'm not sure that either of these are particularly useful--it's
probably better to be explicit about what package you are using at
runtime to lookup/intern names.
--
Peter Seibel peter@xxxxxxxxxxxxxxx
Lisp is the red pill. -- John Fraser, comp.lang.lisp
.
- Follow-Ups:
- Re: package frenzy
- From: Joris Bleys
- Re: package frenzy
- References:
- Re: package frenzy
- From: Peter Seibel
- Re: package frenzy
- From: Joris Bleys
- Re: package frenzy
- Prev by Date: Re: Lisp geographic software
- Next by Date: ANN: First meeting of Danish CL User Group
- Previous by thread: Re: package frenzy
- Next by thread: Re: package frenzy
- Index(es):
Relevant Pages
|
|