[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: intern
From: hplabs!NGALL@G.BBN.COM
Subject: Re: intern
What I would like to see is the following:
1. Leave the stipulation on page 172 that INTERN fix-up the package
slot of an interned symbol.
It may be better to remove the definition of the verb "intern" on pg. 172
since the verb is not used elsewhere in the chapter. See my comments below.
2. Refer to pg. 172 in the def. of INTERN.
I think it would be a better idea to completely define the functionality of
INTERN in one place (preferably on page 184).
3. Make IMPORT also fix up the package slot.
I agree.
4. In UNITERN, after warning about homeless interned symbols, cf.
IMPORT for fixing things up.
5. Make clear that FIND-SYMBOL has NO SIDE EFFECTS. And point out
that it is the only way of mapping a name to a homeless interned
symbol.
For the reasons described below, I would suggest stating that INTERN also
does not modify already-existing symbols.
How 'bout it?!
This appears O.K. at first, but consider the following example:
(in-package "FOO")
(intern "X")
(export 'x)
(in-package "BAR" :use '("FOO"))
(export 'foo:x)
(unintern 'foo:x (find-package "FOO"))
(in-package "BAZ" :use '("BAR"))
(intern "X")
If we follow the proposed definition of intern, x is now internally available
in BAR, available by inheritance in BAZ, but its package cell is BAZ. Now,
if we (unintern 'bar:x (find-package "BAR")), then the symbol will
disappear even though its home package was not BAR. Alternately, if we
(unuse-package "BAR" (find-package "BAZ")), then bar:x has a home package of
BAZ, but is not available in BAZ. This seems to violate print-read consinstency.
(in-package "FOOBAR")
(eq
(read-from-string (with-output-to-string (*standard-output*) (print 'bar:x)))
'bar:x))
This will return nil, instead of t.
An alternative is to have intern not set the home package, but be functionally
equivalent to:
(defun intern (name &optional (package *package*))
(or (find-symbol name package)
(import (make-symbol name) package))))
This has the unfortunate property of having intern return uninterned symbols
in some cases. See the above example.
It seems that we are back to the original statement you made that IMPORT is
the only function permitted to change the package cell (however, the reasons
are more complicated than first suspected). Would anyone care to comment on
this?
By the way, it may be a good idea to make the shadowing-import explicitly
state the same clarification.
I suspect that the (defun intern ...) I stated above is close to what most
people implemented.