From: budden
Subject: use-package & name conflict: why they are not deferred?
Date: 
Message-ID: <91d25b53-83f8-443f-bd25-270146161759@d45g2000hsc.googlegroups.com>
Hallo, group!

Yes, I have read CL standard. But I think standard is stupid in that:

(defpackage :p1 (:exports :sym :sym1))
(defpackage :p2 (:exports :sym :sym2))
(use-package :p1)
(use-package :p2) ; error occurs here

'sym ; but read error should occur here instead

Let us compare lisp's behaviour to that of SQL:

create table p1 (sym int, sym1 int)
create table p2 (sym int, sym2 int)

select sym1, sym2 from p1 inner join p2 on sym1=sym2 -- no error!

select sym from p1 inner join p2 on sym1=sym2 -- error: sym is
ambigious

This behavior is more convinient and it still protects from error;

I've seen http://www.tfeb.org/lisp/hax.html#CONDUITS by Tim Bradshaw
and even tried them. Yes, it was possible to make :iterate package to
live aside with "collecting" macro (synonyms were used too).
But I don't think this is simple enough. In fact, it requires
redefining of large amount of packages. It is especially difficult
when you are trying to install complex system containing from several
packages of different vendors (e.g. I had trouble with (:use-
package :symbolicweb)).

If we'd modified lisp behavior in the way I suggested, things would be
much better, I guess.

What do you think about that? Would such a modification popular if it
were made as a patch similar to "conduits"?

From: Barry Margolin
Subject: Re: use-package & name conflict: why they are not deferred?
Date: 
Message-ID: <barmar-A05C4F.23313924102008@mara100-84.onlink.net>
In article 
<····································@d45g2000hsc.googlegroups.com>,
 budden <········@mtu-net.ru> wrote:

> Hallo, group!
> 
> Yes, I have read CL standard. But I think standard is stupid in that:
> 
> (defpackage :p1 (:exports :sym :sym1))
> (defpackage :p2 (:exports :sym :sym2))
> (use-package :p1)
> (use-package :p2) ; error occurs here
> 
> 'sym ; but read error should occur here instead
> 
> Let us compare lisp's behaviour to that of SQL:
> 
> create table p1 (sym int, sym1 int)
> create table p2 (sym int, sym2 int)
> 
> select sym1, sym2 from p1 inner join p2 on sym1=sym2 -- no error!
> 
> select sym from p1 inner join p2 on sym1=sym2 -- error: sym is
> ambigious
> 
> This behavior is more convinient and it still protects from error;

SQL isn't making a change to anything, it just needs to disambiguate a 
single statement at a time.  When you use USE-PACKAGE, you're making a 
change to the current package.  You're saying that the imported symbols 
are part of the current package now.  But you can't have two different 
symbols with the same name in a package.

In general, one doesn't use USE-PACKAGE on the fly like that.  Usually 
it's used as part of defining a new package:

(defpackage :p3 (:use :p1 :p2))

When you define such a package, you should be told that it doesn't make 
sense because it's importing conflicting symbols.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Kaz Kylheku
Subject: Re: use-package & name conflict: why they are not deferred?
Date: 
Message-ID: <20081024203219.227@gmail.com>
On 2008-10-25, Barry Margolin <······@alum.mit.edu> wrote:
>> This behavior is more convinient and it still protects from error;
>
> SQL isn't making a change to anything, it just needs to disambiguate a 
> single statement at a time.  When you use USE-PACKAGE, you're making a 
> change to the current package.  You're saying that the imported symbols 
> are part of the current package now.

You should not use any variation on the verb ``import'' when discussin
USE-PACKAGE, because IMPORT is quite different.

USE-PACKAGE creates visibility from one package to another without actually
importing symbols. The wording is that symbols are ``inherited''.

> But you can't have two different 
> symbols with the same name in a package.

But those symbols aren't really there.
From: Thomas A. Russ
Subject: Re: use-package & name conflict: why they are not deferred?
Date: 
Message-ID: <ymi1vy1hpne.fsf@blackcat.isi.edu>
budden <········@mtu-net.ru> writes:

> Hallo, group!
> 
> Yes, I have read CL standard. But I think standard is stupid in that:
> 
> (defpackage :p1 (:exports :sym :sym1))
> (defpackage :p2 (:exports :sym :sym2))
> (use-package :p1)
> (use-package :p2) ; error occurs here

USE-PACKAGE is really meant as a convenience and as such it isn't
necessarily the best choice for having careful software engineering in
large projects.

The best programming practice would be to not use USE-PACKAGE and
instead to use IMPORT-FROM, where you explicitly identify which symbols
you want to use.

Even better practice is to do this all in the DEFPACKAGE form for your
current package, thus:

 (defpackage :p1 (:exports :sym :sym1))
 (defpackage :p2 (:exports :sym :sym2))
 (defpackage :my-pkg
    (:import-from :p1 :sym1) 
    (:import-from :p2 :sym2))

That way you have full control over your package contents, there are no
surprises, and if the packages P1 and P2 add additional symbols later,
they won't cause you any problems.

-- 
Thomas A. Russ,  USC/Information Sciences Institute