From: charlie
Subject: Packages and CLOS
Date: 
Message-ID: <1117627468.983773.10240@f14g2000cwb.googlegroups.com>
Hi,
   I have been having a little trouble with a combination of packages
and CLOS methods. For example:
I have a method "text" in package P1 that acts on an object
"text-object" defined in P1 and then I create a package P2 that :uses
P1 and I create an text-object2 inherited from text-object and define a
text method for that object. Next I use the "text" method on a
"text-object" (P1) created in P2 and get an error because lisp doesn't
know if I mean P1:text or P2:text.

I know that they are part of the same object hierarchy and so it
shouldn't matter.
I think I understand why it happens (they are really different symbols)
but how can I get around it and just be able to use "text" in my P2 and
not worry? Looking at the defpackage HS it looks like :import-from
might be the answer but it also looks like that might make an even
bigger tangle plus I'd rather not have to name every symbol from P1.

Thanks,
Charlieb.

From: Pascal Costanza
Subject: Re: Packages and CLOS
Date: 
Message-ID: <3g5nkgFapngbU1@individual.net>
charlie wrote:
> Hi,
>    I have been having a little trouble with a combination of packages
> and CLOS methods. For example:
> I have a method "text" in package P1 that acts on an object
> "text-object" defined in P1 and then I create a package P2 that :uses
> P1 and I create an text-object2 inherited from text-object and define a
> text method for that object. Next I use the "text" method on a
> "text-object" (P1) created in P2 and get an error because lisp doesn't
> know if I mean P1:text or P2:text.
> 
> I know that they are part of the same object hierarchy and so it
> shouldn't matter.
> I think I understand why it happens (they are really different symbols)
> but how can I get around it and just be able to use "text" in my P2 and
> not worry? Looking at the defpackage HS it looks like :import-from
> might be the answer but it also looks like that might make an even
> bigger tangle plus I'd rather not have to name every symbol from P1.

Why don't you just export text from P1? (with the :export option in 
defpackage...)


Pascal

-- 
2nd European Lisp and Scheme Workshop
July 26 - Glasgow, Scotland - co-located with ECOOP 2005
http://lisp-ecoop05.bknr.net/
From: Pascal Bourguignon
Subject: Re: Packages and CLOS
Date: 
Message-ID: <87is0y9sbs.fsf@thalassa.informatimago.com>
"charlie" <···············@gmail.com> writes:
>    I have been having a little trouble with a combination of packages
> and CLOS methods. For example:
> I have a method "text" in package P1 that acts on an object
> "text-object" defined in P1 and then I create a package P2 that :uses
> P1 and I create an text-object2 inherited from text-object and define a
> text method for that object. Next I use the "text" method on a
> "text-object" (P1) created in P2 and get an error because lisp doesn't
> know if I mean P1:text or P2:text.
>
> I know that they are part of the same object hierarchy and so it
> shouldn't matter.
> I think I understand why it happens (they are really different symbols)
> but how can I get around it and just be able to use "text" in my P2 and
> not worry? Looking at the defpackage HS it looks like :import-from
> might be the answer but it also looks like that might make an even
> bigger tangle plus I'd rather not have to name every symbol from P1.

If you want to overwrite the p1:text method in package p2, then you can write:

(defmethod p1:text ((self text-object2)) ...)

or of course, you could set up things such as (eq 'p2:text p1:text),
for example with:

(in-package "P2")
(import 'p1:text)
(defmethod text ((self text-object2)) ...)

or:

(defpackage "P2"
  (:use "COMMON-LISP" "P1"))
(in-package "P2")
(defmethod text ((self text-object2)) ...)


But you did export text from p1 didn't you?

(defpackage "P1"
  (:use "COMMON-LISP")
  (:export "TEXT"))




-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Grace personified,
I leap into the window.
I meant to do that.
From: charlie
Subject: Re: Packages and CLOS
Date: 
Message-ID: <1117630281.030262.171670@z14g2000cwz.googlegroups.com>
Yes, you're quite right. I made a mistake and misinterpreted the error
message to be the problem I described. When in fact it was the one you
just described. Doh!
Thanks for the help.
Charlieb.