From: jakemiles
Subject: strange results when obtaining a package's symbols
Date: 
Message-ID: <1167087554.094892.3350@79g2000cws.googlegroups.com>
Hello.  I'm trying to obtain the names of all functions defined in a
package, in order to generate a test function skeleton for each one.
The following code returns the names of symbols in the package I
specify, but also includes a few function symbols that are no longer in
that package, and also includes names of local variables in some of the
functions.  This happens even when I restart emacs.  I'm using emacs +
slime + cmucl.  Does anyone know where these old and random symbols are
coming from?  I've tried deleting all .ppcf files in the directory
containing these functions and the 'list package.

- Jake

;; the evaluated form
(package:package-symbol-names 'list)

;; the functions it uses (in a package called :package)
(defun package-symbols (package &key (external t) (internal t)
(inherited nil))
  (mapcar #'car (package-symbol-access-pairs package
					     :external external
					     :internal internal
					     :inherited inherited)))


(defun package-symbol-names (package &key (external t) (internal t)
(inherited nil))
  (mapcar #'symbol-name
	  (package-symbols package
			   :external external
			   :internal internal
			   :inherited inherited)))


(defun package-symbol-access-pairs (package &key (external t) (internal
t) (inherited nil))
  (remove-if-not (lambda (symbol-access-pair)
		   (let ((accessibility (cdr symbol-access-pair)))
		     (or (and external (eq accessibility :external))
			 (and internal (eq accessibility :internal))
			 (and inherited (eq accessibility :inherited)))))
  (all-package-symbol-access-pairs package)))


(defun all-package-symbol-access-pairs (package)
  (let ((all-symbols))
    (do-symbols (x package)
      (multiple-value-bind (symbol accessibility)
	  (find-symbol (symbol-name x) package)
	(push (cons symbol accessibility) all-symbols)))
    all-symbols))

From: Barry Margolin
Subject: Re: strange results when obtaining a package's symbols
Date: 
Message-ID: <barmar-11C1E3.18100525122006@comcast.dca.giganews.com>
In article <······················@79g2000cws.googlegroups.com>,
 "jakemiles" <···········@gmail.com> wrote:

> Hello.  I'm trying to obtain the names of all functions defined in a
> package, in order to generate a test function skeleton for each one.
> The following code returns the names of symbols in the package I
> specify, but also includes a few function symbols that are no longer in
> that package, and also includes names of local variables in some of the
> functions.  This happens even when I restart emacs.  I'm using emacs +
> slime + cmucl.  Does anyone know where these old and random symbols are
> coming from?  I've tried deleting all .ppcf files in the directory
> containing these functions and the 'list package.

Nothing in your code checks whether a symbol names a function, so why do 
you expect it to only return those symbols?  Your call will return all 
the internal and external symbols in the LIST package, regardless of how 
they've been used.

> 
> - Jake
> 
> ;; the evaluated form
> (package:package-symbol-names 'list)
> 
> ;; the functions it uses (in a package called :package)
> (defun package-symbols (package &key (external t) (internal t)
> (inherited nil))
>   (mapcar #'car (package-symbol-access-pairs package
> 					     :external external
> 					     :internal internal
> 					     :inherited inherited)))
> 
> 
> (defun package-symbol-names (package &key (external t) (internal t)
> (inherited nil))
>   (mapcar #'symbol-name
> 	  (package-symbols package
> 			   :external external
> 			   :internal internal
> 			   :inherited inherited)))
> 
> 
> (defun package-symbol-access-pairs (package &key (external t) (internal
> t) (inherited nil))
>   (remove-if-not (lambda (symbol-access-pair)
> 		   (let ((accessibility (cdr symbol-access-pair)))
> 		     (or (and external (eq accessibility :external))
> 			 (and internal (eq accessibility :internal))
> 			 (and inherited (eq accessibility :inherited)))))
>   (all-package-symbol-access-pairs package)))
> 
> 
> (defun all-package-symbol-access-pairs (package)
>   (let ((all-symbols))
>     (do-symbols (x package)
>       (multiple-value-bind (symbol accessibility)
> 	  (find-symbol (symbol-name x) package)
> 	(push (cons symbol accessibility) all-symbols)))
>     all-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: jakemiles
Subject: Re: strange results when obtaining a package's symbols
Date: 
Message-ID: <1167088690.613900.55970@79g2000cws.googlegroups.com>
That was going to be my next question - how I determine if a symbol
names a function without triggering an error.  But even as the code
stands now I don't understand how it even still knows about some of the
symbols it's returning - they don't appear anywhere in the file (though
they used to).


Barry Margolin wrote:
> In article <······················@79g2000cws.googlegroups.com>,
>  "jakemiles" <···········@gmail.com> wrote:
>
> > Hello.  I'm trying to obtain the names of all functions defined in a
> > package, in order to generate a test function skeleton for each one.
> > The following code returns the names of symbols in the package I
> > specify, but also includes a few function symbols that are no longer in
> > that package, and also includes names of local variables in some of the
> > functions.  This happens even when I restart emacs.  I'm using emacs +
> > slime + cmucl.  Does anyone know where these old and random symbols are
> > coming from?  I've tried deleting all .ppcf files in the directory
> > containing these functions and the 'list package.
>
> Nothing in your code checks whether a symbol names a function, so why do
> you expect it to only return those symbols?  Your call will return all
> the internal and external symbols in the LIST package, regardless of how
> they've been used.
>
> >
> > - Jake
> >
> > ;; the evaluated form
> > (package:package-symbol-names 'list)
> >
> > ;; the functions it uses (in a package called :package)
> > (defun package-symbols (package &key (external t) (internal t)
> > (inherited nil))
> >   (mapcar #'car (package-symbol-access-pairs package
> > 					     :external external
> > 					     :internal internal
> > 					     :inherited inherited)))
> >
> >
> > (defun package-symbol-names (package &key (external t) (internal t)
> > (inherited nil))
> >   (mapcar #'symbol-name
> > 	  (package-symbols package
> > 			   :external external
> > 			   :internal internal
> > 			   :inherited inherited)))
> >
> >
> > (defun package-symbol-access-pairs (package &key (external t) (internal
> > t) (inherited nil))
> >   (remove-if-not (lambda (symbol-access-pair)
> > 		   (let ((accessibility (cdr symbol-access-pair)))
> > 		     (or (and external (eq accessibility :external))
> > 			 (and internal (eq accessibility :internal))
> > 			 (and inherited (eq accessibility :inherited)))))
> >   (all-package-symbol-access-pairs package)))
> >
> >
> > (defun all-package-symbol-access-pairs (package)
> >   (let ((all-symbols))
> >     (do-symbols (x package)
> >       (multiple-value-bind (symbol accessibility)
> > 	  (find-symbol (symbol-name x) package)
> > 	(push (cons symbol accessibility) all-symbols)))
> >     all-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: Zach Beane
Subject: Re: strange results when obtaining a package's symbols
Date: 
Message-ID: <m3bqlr7e66.fsf@unnamed.xach.com>
"jakemiles" <···········@gmail.com> writes:

> That was going to be my next question - how I determine if a symbol
> names a function without triggering an error. 

FBOUNDP.

> But even as the code stands now I don't understand how it even still
> knows about some of the symbols it's returning - they don't appear
> anywhere in the file (though they used to).

CL systems can evolve without restarting. The files on disk can be
used to initialize the system, but there's no guarantee that they
represent the current state.

Zach
From: Barry Margolin
Subject: Re: strange results when obtaining a package's symbols
Date: 
Message-ID: <barmar-DB73C6.14184926122006@comcast.dca.giganews.com>
In article <··············@unnamed.xach.com>,
 Zach Beane <····@xach.com> wrote:

> "jakemiles" <···········@gmail.com> writes:
> 
> > That was going to be my next question - how I determine if a symbol
> > names a function without triggering an error. 
> 
> FBOUNDP.
> 
> > But even as the code stands now I don't understand how it even still
> > knows about some of the symbols it's returning - they don't appear
> > anywhere in the file (though they used to).
> 
> CL systems can evolve without restarting. The files on disk can be
> used to initialize the system, but there's no guarantee that they
> represent the current state.

But he said he *did* restart.  Actually, he said he restarted Emacs; I 
assume the CMUCL process being run from SLIME is subordinate, so that 
should restart Lisp as well.

Did you recompile all the FASL files?  If not, that may be where the old 
symbols are coming from.

-- 
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 ***