From: Frank Goenninger DG1SBG
Subject: finding package name of a symbol at execution time
Date: 
Message-ID: <lzy7fvpz0x.fsf@pcsde001.de.goenninger.net>
Hi -

In the quest of writing some debug print functions I am trying to find
out the package in which a given symbol (of a function) is defined
in...

I currently only get the current package I am *using* the symbol
in.

Code used so far:

  (format *debug-io* "~&*** ~A [ PKG ~A, FN ~A ( ~A ) ]~&"
	  msg-class (package-name *package*) method method-desc)

Oh - just a thought: if I do this as a macro at compile and
load-time ... Let's see (hacking away in other Emacs buffer) -
Any ideas? Thx!

Frank

-- 

  Frank Goenninger

  frgo(at)mac(dot)com

  "Don't ask me! I haven't been reading comp.lang.lisp long enough to 
  really know ..."

From: Pillsy
Subject: Re: finding package name of a symbol at execution time
Date: 
Message-ID: <1188309243.479127.252180@50g2000hsm.googlegroups.com>
On Aug 28, 9:30 am, Frank Goenninger DG1SBG <·············@nomail.org>
wrote:

> In the quest of writing some debug print functions I am trying to find
> out the package in which a given symbol (of a function) is defined
> in...

> I currently only get the current package I am *using* the symbol
> in.

You can get a list of all the packages it might be defined in, and
then see which package (if any) it's actually defined in. First check
to see if it's an :INTERNAL or :EXTERNAL symbol of *PACKAGE*, and then
see if it's an :EXTERNAL symbol of any of the packages that *PACKAGE*
uses. Like so:

(defun find-package-defining-symbol (designator)
  (let ((name (string designator)))
    (labels ((in-package-p (package)
	      (nth-value 1 (find-symbol name package))))
     (if (member (in-package-p *package*) '(:external :internal))
	 *package*
	 (find :external (package-use-list *package*) :key #'in-package-
p)))))

Cheers,
Pillsy
From: Frank Goenninger DG1SBG
Subject: Re: finding package name of a symbol at execution time
Date: 
Message-ID: <lzps17px31.fsf@pcsde001.de.goenninger.net>
Pillsy <·········@gmail.com> writes:

> You can get a list of all the packages it might be defined in, and
> then see which package (if any) it's actually defined in. First check
> to see if it's an :INTERNAL or :EXTERNAL symbol of *PACKAGE*, and then
> see if it's an :EXTERNAL symbol of any of the packages that *PACKAGE*
> uses. Like so:
>
> (defun find-package-defining-symbol (designator)
>   (let ((name (string designator)))
>     (labels ((in-package-p (package)
> 	      (nth-value 1 (find-symbol name package))))
>      (if (member (in-package-p *package*) '(:external :internal))
> 	 *package*
> 	 (find :external (package-use-list *package*) :key #'in-package-
> p)))))
>
> Cheers,
> Pillsy
>

I love it! Another example of "a simple question asked - got answers
at light speed - learned a lot more than I hoped for." This is c.l.l
at its best!

Thanks!!!

Frank
From: Rob Warnock
Subject: Re: finding package name of a symbol at execution time
Date: 
Message-ID: <irCdndNnqZXstEjbnZ2dnUVZ_ofinZ2d@speakeasy.net>
Pillsy  <·········@gmail.com> wrote:
+---------------
| Frank Goenninger DG1SBG <·············@nomail.org> wrote:
| > I currently only get the current package I am *using* the symbol
| > in.
| 
| You can get a list of all the packages it might be defined in, and
| then see which package (if any) it's actually defined in. First check
| to see if it's an :INTERNAL or :EXTERNAL symbol of *PACKAGE*, and then
| see if it's an :EXTERNAL symbol of any of the packages that *PACKAGE*
| uses. Like so:
| 
| (defun find-package-defining-symbol (designator)
|   (let ((name (string designator)))
|     (labels ((in-package-p (package)
| 	      (nth-value 1 (find-symbol name package))))
|      (if (member (in-package-p *package*) '(:external :internal))
| 	 *package*
| 	 (find :external (package-use-list *package*) :key #'in-package-p)))))
+---------------

More generally, don't forget about APROPOS-LIST.
Not applicable to the OP's problem, but can often
be useful in user-written debugging aids.


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Zach Beane
Subject: Re: finding package name of a symbol at execution time
Date: 
Message-ID: <m3k5rfai96.fsf@unnamed.xach.com>
Frank Goenninger DG1SBG <·············@nomail.org> writes:

> In the quest of writing some debug print functions I am trying to find
> out the package in which a given symbol (of a function) is defined
> in...

Does SYMBOL-PACKAGE do what you need?

Zach
From: Frank Goenninger DG1SBG
Subject: Re: finding package name of a symbol at execution time
Date: 
Message-ID: <lztzqjpxb8.fsf@pcsde001.de.goenninger.net>
Zach Beane <····@xach.com> writes:

> Frank Goenninger DG1SBG <·············@nomail.org> writes:
>
>> In the quest of writing some debug print functions I am trying to find
>> out the package in which a given symbol (of a function) is defined
>> in...
>
> Does SYMBOL-PACKAGE do what you need?
>
> Zach

Yes, thanks!!

Frank