Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Interpretation of IMPORT

46 views
Skip to first unread message

Zach Beane

unread,
Dec 21, 2011, 12:49:55 PM12/21/11
to
What do you get when you call the following function?

(defun apparently-uninterned-import ()
(let ((foo (make-package "FOO" :use nil))
(bar (make-package "BAR" :use nil)))
(with-output-to-string (*standard-output*)
(let ((symbol (intern "A" foo)))
(write symbol)
(write-char #\Space)
(import symbol bar)
(unintern symbol foo)
(write symbol)
(write-char #\Space)
(when (eql (nth-value 1 (find-symbol "A" bar))
:internal)
(write 'present)
(write-char #\Space))
(import symbol bar)
(write symbol))
(delete-package foo)
(delete-package bar))))

From some CLs I get this:

"FOO::A #:A PRESENT BAR::A"

For others I get this:

"FOO::A #:A PRESENT #:A"

Which one is right?

Zach

Pascal J. Bourguignon

unread,
Dec 21, 2011, 1:16:34 PM12/21/11
to
IIRC, both are right.

--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.

Zach Beane

unread,
Dec 21, 2011, 1:40:56 PM12/21/11
to
"Pascal J. Bourguignon" <p...@informatimago.com> writes:

>> From some CLs I get this:
>>
>> "FOO::A #:A PRESENT BAR::A"
>>
>> For others I get this:
>>
>> "FOO::A #:A PRESENT #:A"
>>
>> Which one is right?
>
> IIRC, both are right.

Why?

Zach

Kaz Kylheku

unread,
Dec 21, 2011, 3:02:22 PM12/21/11
to
On 2011-12-21, Zach Beane <xa...@xach.com> wrote:
> What do you get when you call the following function?
>
> (defun apparently-uninterned-import ()

Ron Garret emerges from the machine and whacks you over the head
with a printed copy of the HyperSpec.

Zach Beane

unread,
Dec 21, 2011, 3:10:15 PM12/21/11
to
Morely likely a copy of CLtL2.

Zach

Barry Margolin

unread,
Dec 21, 2011, 3:44:31 PM12/21/11
to
In article <87r4zxr...@kuiper.lan.informatimago.com>,
I disagree, the first is right.

UNINTERN says "If _package_ is the home package for _symbol_, _symbol_
is made to have no home package." So after (unintern symbol foo), A has
no home package.

IMPORT says "If any symbol to be imported has no home package (i.e.,
(symbol-package symbol) => nil), import sets the home package of the
symbol to _package_." So (import symbol bar) is supposed to set the home
package to BAR.

CLTL1 didn't specify the latter behavior, but it was clarified in ANSI
CL.

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Zach Beane

unread,
Dec 21, 2011, 3:47:59 PM12/21/11
to
Barry Margolin <bar...@alum.mit.edu> writes:

>> > From some CLs I get this:
>> >
>> > "FOO::A #:A PRESENT BAR::A"
>> >
>> > For others I get this:
>> >
>> > "FOO::A #:A PRESENT #:A"
>> >
>> > Which one is right?
>>
>> IIRC, both are right.
>
> I disagree, the first is right.
>
> UNINTERN says "If _package_ is the home package for _symbol_, _symbol_
> is made to have no home package." So after (unintern symbol foo), A has
> no home package.
>
> IMPORT says "If any symbol to be imported has no home package (i.e.,
> (symbol-package symbol) => nil), import sets the home package of the
> symbol to _package_." So (import symbol bar) is supposed to set the home
> package to BAR.

IMPORT also says "If the symbol is already present in the importing
package, import has no effect." The symbol is already present in this
scenario. Is changing the home package of the symbol an effect?

Zach

Barry Margolin

unread,
Dec 21, 2011, 3:52:28 PM12/21/11
to
In article <87d3bhw...@hangup.portland.xach.com>,
Ahh, I missed the earlier import. That is indeed an ambiguity.

Kaz Kylheku

unread,
Dec 21, 2011, 4:09:43 PM12/21/11
to
On 2011-12-21, Zach Beane <xa...@xach.com> wrote:
> Kaz Kylheku <k...@kylheku.com> writes:
>
>> On 2011-12-21, Zach Beane <xa...@xach.com> wrote:
>>> What do you get when you call the following function?
>>>
>>> (defun apparently-uninterned-import ()
>>
>> Ron Garret emerges from the machine and whacks you over the head
>> with a printed copy of the HyperSpec.
>
> Morely likely a copy of CLtL2.

Yeah! You know, I was going to write CLtL2!

Mattias Nilsson

unread,
Dec 22, 2011, 7:03:59 AM12/22/11
to
On Dec 21, 9:47 pm, Zach Beane <x...@xach.com> wrote:
> Barry Margolin <bar...@alum.mit.edu> writes:
> >> > From some CLs I get this:
>
> >> >   "FOO::A #:A PRESENT BAR::A"
>
> >> > For others I get this:
>
> >> >   "FOO::A #:A PRESENT #:A"
>
> >> > Which one is right?
>
> >> IIRC, both are right.
>
> > I disagree, the first is right.
>
> > UNINTERN says "If _package_ is the home package for _symbol_, _symbol_
> > is made to have no home package." So after (unintern symbol foo), A has
> > no home package.
>
> > IMPORT says "If any symbol to be imported has no home package (i.e.,
> > (symbol-package symbol) => nil), import sets the home package of the
> > symbol to _package_."

I think the key part here is: "to be imported"; which is not the case
in
your code because of the following:

> IMPORT also says "If the symbol is already present in the importing
> package, import has no effect."

This would mean that the second observed result is the correct one.

Mattias
0 new messages