From: Mike
Subject: set of defuns?
Date: 
Message-ID: <10ngnr0loa8aq6b@corp.supernews.com>
Is there some (portable) method of getting a list of all the defuns,
defvars, defmacros, etc., in a LISP system? The idea is like the 'words'
command/function/word in FORTH.

Mike

From: Barry Margolin
Subject: Re: set of defuns?
Date: 
Message-ID: <barmar-C37671.21360721102004@comcast.dca.giganews.com>
In article <···············@corp.supernews.com>,
 Mike <·····@mikee.ath.cx> wrote:

> Is there some (portable) method of getting a list of all the defuns,
> defvars, defmacros, etc., in a LISP system? The idea is like the 'words'
> command/function/word in FORTH.
> 
> Mike

(defun list-all-functions ()
  (do-all-symbols (s)
    (when (fboundp s) (print s))))

LIST-ALL-MACROS is left as an exercise for the reader.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Pascal Bourguignon
Subject: Re: set of defuns?
Date: 
Message-ID: <87is93y15o.fsf@thalassa.informatimago.com>
Barry Margolin <······@alum.mit.edu> writes:

> In article <···············@corp.supernews.com>,
>  Mike <·····@mikee.ath.cx> wrote:
> 
> > Is there some (portable) method of getting a list of all the defuns,
> > defvars, defmacros, etc., in a LISP system? The idea is like the 'words'
> > command/function/word in FORTH.
> > 
> > Mike
> 
> (defun list-all-functions ()
>   (do-all-symbols (s)
>     (when (fboundp s) (print s))))
> 
> LIST-ALL-MACROS is left as an exercise for the reader.

The more so when:

(defmacro test (&rest args) nil)
(fboundp 'test) ==> T

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Voting Democrat or Republican is like choosing a cabin in the Titanic.
From: Thomas A. Russ
Subject: Re: set of defuns?
Date: 
Message-ID: <ymiwtxi8fcc.fsf@sevak.isi.edu>
> In article <···············@corp.supernews.com>,
>  Mike <·····@mikee.ath.cx> wrote:
> 
> > Is there some (portable) method of getting a list of all the defuns,
> > defvars, defmacros, etc., in a LISP system? The idea is like the 'words'
> > command/function/word in FORTH.

One other simple method is

(apropos "")

but it will often suffer from issues like the variable, function and
class name.

Nevertheless, it is perhaps a useful thing to be aware of as a newby...

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Thomas A. Russ
Subject: Re: set of defuns?
Date: 
Message-ID: <ymivfd28fb5.fsf@sevak.isi.edu>
> In article <···············@corp.supernews.com>,
>  Mike <·····@mikee.ath.cx> wrote:
> 
> > Is there some (portable) method of getting a list of all the defuns,
> > defvars, defmacros, etc., in a LISP system? The idea is like the 'words'
> > command/function/word in FORTH.

One other simple method is

(apropos "")

but it will often suffer from issues like the variable, function and
class name.

Nevertheless, it is perhaps a useful thing to be aware of as a newby,
especially since it takes a substring argument that can reduce the
number of  results returned.

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Pascal Bourguignon
Subject: Re: set of defuns?
Date: 
Message-ID: <87mzyfy19k.fsf@thalassa.informatimago.com>
Mike <·····@mikee.ath.cx> writes:

> Is there some (portable) method of getting a list of all the defuns,
> defvars, defmacros, etc., in a LISP system? The idea is like the 'words'
> command/function/word in FORTH.
> 
> Mike

(do-external-symbols (s "COMMON-LISP")
    (when (fboundp s) 
      (format t "~40A : ~A~%" s
         (cond
            ((special-operator-p s) "special-operator")
            ((macro-function s) "macro")
            (t "function"))))
    (when (boundp s)
      (format t "~40A : ~A~%" s
          (cond
            ((constantp s) "constant variable")
            (t "variable")))))

       
-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Voting Democrat or Republican is like choosing a cabin in the Titanic.
From: Bill Clementson
Subject: Re: set of defuns?
Date: 
Message-ID: <1b3ac8a3.0410220740.3321ea56@posting.google.com>
Pascal Bourguignon <····@mouse-potato.com> wrote in message news:<··············@thalassa.informatimago.com>...
> Mike <·····@mikee.ath.cx> writes:
> 
> > Is there some (portable) method of getting a list of all the defuns,
> > defvars, defmacros, etc., in a LISP system? The idea is like the 'words'
> > command/function/word in FORTH.
> > 
> > Mike
> 
> (do-external-symbols (s "COMMON-LISP")
>     (when (fboundp s) 
>       (format t "~40A : ~A~%" s
>          (cond
>             ((special-operator-p s) "special-operator")
>             ((macro-function s) "macro")
>             (t "function"))))
>     (when (boundp s)
>       (format t "~40A : ~A~%" s
>           (cond
>             ((constantp s) "constant variable")
>             (t "variable")))))

Nice. However, in order to be complete, wouldn't you also need to show
unbound symbols? Here is my version:
http://home.comcast.net/~bc19191/blog/041022.html

--
Bill Clementson
From: Szymon
Subject: Re: set of defuns?
Date: 
Message-ID: <87mzyevdtd.fsf@eva.rplacd.net>
···············@yahoo.com (Bill Clementson) writes:

> [.....]

> Nice. However, in order to be complete, wouldn't you also need to show
> unbound symbols? Here is my version:
> http://home.comcast.net/~bc19191/blog/041022.html

I think my version of your code is more blog-friendly (yours is too 'fat'):

(mapcar (lambda (package)
	  (mapcar (lambda (x) 
		    (format t "~a: ~a(~a)~%" (package-name package) (car x) (cadr x)))
		  (list-all-symbols package)))
	(list-all-packages))


(defun list-all-symbols (package)
  (sort (loop for sym being each external-symbol of package
	      when (and (fboundp sym)
			(not (or (special-operator-p sym)
				 (boundp sym)
				 (macro-function sym))))
	      collect (list sym "Function")
	      when (macro-function sym) collect (list sym "Macro")
	      when (and (boundp sym) (constantp sym)) collect (list sym "Constant")
	      when (and (boundp sym) (not (constantp sym))) collect (list sym "Variable")
	      when (special-operator-p sym) collect (list sym "Special Operator")
	      when (not (or (fboundp sym) (special-operator-p sym) (boundp sym) (macro-function sym)))
	      collect (list sym "Unbound Symbol"))
	#'string-lessp :key #'car))

;; ---------------------------------------------------------------------------------------
;; my version
;; ---------------------------------------------------------------------------------------

(loop for package in (list-all-packages)
      do (flet ((f (a)
		   (format t  "~A: ~{~A~^ is ~}~%" (package-name package) a)))
	   (mapc #'f (list-all-symbols package))))


(defun list-all-symbols (package)
  (sort
   (loop for sym being each external-symbol of package collect
	 (list sym
	       (cond ((and (fboundp sym)
			   (not (or (special-operator-p sym) (boundp sym) (macro-function sym))))
		      "Function")
		     ((macro-function sym)
		      "Macro")
	             ((and (boundp sym) (constantp sym))
		      "Constant")
	             ((and (boundp sym) (not (constantp sym)))
		      "Variable")
                     ((special-operator-p sym)
		      "Special Operator")
	             ((not (or (fboundp sym) (special-operator-p sym) (boundp sym) (macro-function sym)))
		      "Unbound Symbol"))))
   #'string-lessp :key #'car))

;; ---------------------------------------------------------------------------------------

Regards, Szymon.
From: Marco Baringer
Subject: Re: set of defuns?
Date: 
Message-ID: <m2ekjqvdrp.fsf@bese.it>
Szymon <············@o2.pl> writes:

> (defun list-all-symbols (package)
>   (sort
>    (loop for sym being each external-symbol of package collect
> 	 (list sym
> 	       (cond ((and (fboundp sym)
> 			   (not (or (special-operator-p sym) (boundp sym) (macro-function sym))))
> 		      "Function")
> 		     ((macro-function sym)
> 		      "Macro")
> 	             ((and (boundp sym) (constantp sym))
> 		      "Constant")
> 	             ((and (boundp sym) (not (constantp sym)))
> 		      "Variable")
>                      ((special-operator-p sym)
> 		      "Special Operator")
> 	             ((not (or (fboundp sym) (special-operator-p sym) (boundp sym) (macro-function sym)))
> 		      "Unbound Symbol"))))
>    #'string-lessp :key #'car))

this seems to assume that a symbol can't be more than one thing. (for
CL:+ this would say it's a variable).

-- 
-Marco
Ring the bells that still can ring.
Forget your perfect offering.
There is a crack in everything.
That's how the light gets in.
     -Leonard Cohen
From: Szymon
Subject: Re: set of defuns?
Date: 
Message-ID: <87ekjqva53.fsf@eva.rplacd.net>
"Marco Baringer" <··@bese.it> writes:


> [.....]

> this seems to assume that a symbol can't be more than one thing. (for
> CL:+ this would say it's a variable).

eh, stupid me...

(defun list-all-symbols (package)
  (sort
   (loop for sym being each external-symbol of package collect
	 (remove nil
		 (list sym
		       (if (and (fboundp sym)
				(not (special-operator-p sym))
				(not (macro-function sym)))
			   "Function")
		       (if (macro-function sym)
			   "Macro")
		       (if (and (boundp sym) (constantp sym))
			   "Constant")
		       (if (and (boundp sym) (not (constantp sym)))
			   "Variable")
		       (if (special-operator-p sym)
			   "Special Operator")
		       (if (and (not (fboundp sym)) (not (boundp sym)))
			   "Unbound Symbol"))))
   #'string-lessp :key #'car))

Regards, Szymon.
From: Szymon
Subject: Re: set of defuns?
Date: 
Message-ID: <87is92va6x.fsf@eva.rplacd.net>
···············@yahoo.com (Bill Clementson) writes:

> Nice. However, in order to be complete, wouldn't you also need to show
> unbound symbols? Here is my version:
> http://home.comcast.net/~bc19191/blog/041022.html

My version:

(defun list-all-symbols (package)
  (sort
   (loop for sym being each external-symbol of package collect
	 (remove nil
		 (list sym
		       (if (and (fboundp sym)
				(not (special-operator-p sym))
				(not (macro-function sym)))
			   "Function")
		       (if (macro-function sym)
			   "Macro")
		       (if (and (boundp sym) (constantp sym))
			   "Constant")
		       (if (and (boundp sym) (not (constantp sym)))
			   "Variable")
		       (if (special-operator-p sym)
			   "Special Operator")
		       (if (and (not (fboundp sym)) (not (boundp sym)))
			   "Unbound Symbol"))))
   #'string-lessp :key #'car))



(loop for package in (list-all-packages)
      do (flet ((f (a)
		   (format t  "~A: ~A is ~{~A~^ and ~}.~%" (package-name package) (car a) (cdr a))))
	   (mapc #'f (list-all-symbols package))))



Regards, Szymon.
From: Christopher C. Stacy
Subject: Re: set of defuns?
Date: 
Message-ID: <uis93s95n.fsf@news.dtpq.com>
See also the APROPOS function, which might be what you
wanted (or at least related to it) in the first place.

See also the newsgroup thread about "regexp-apropos", 
which someone here invented.
From: Marco Baringer
Subject: Re: set of defuns?
Date: 
Message-ID: <m2mzyewvhz.fsf@bese.it>
Mike <·····@mikee.ath.cx> writes:

> Is there some (portable) method of getting a list of all the defuns,
> defvars, defmacros, etc., in a LISP system? The idea is like the 'words'
> command/function/word in FORTH.

this is probably WAY more than you want but i figure you can use bits
and pieces to build up whatever introspection functions you need.

(defun symbol-info (symbol)
  "Print information about the symbol SYMBOL.

[based on slime's symbol inspector]"
  (flet ((info-line (tag value)
           (format t "~A: ~S~%" tag value))
         (doc-when (type)
           (when (documentation symbol type)
             (format t "Documentation:~%~A~&"
                     (documentation symbol type)))))
    (info-line "Name" (symbol-name symbol))
    (info-line "Package" (symbol-package symbol))
    (info-line "Status" (nth-value 1 (intern (symbol-name symbol)
                                             (symbol-package symbol))))
    ;; variable binding
    (cond
      ((constantp symbol)
       (info-line "It is a constant of value" (symbol-value symbol)))
      ((boundp symbol)
       (info-line "It is a global variable bound to"
                  (symbol-value symbol)))
      ((nth-value 1 (macroexpand symbol))
       (info-line "It is a symbol macro with expansion"
                  (macroexpand symbol)))
      (t
       (format t "It is unbound.~%")))
    (doc-when 'variable)
    ;; function binding
    (if (fboundp symbol)
        (progn
          (if (macro-function symbol)
              (info-line "It a macro with macro-function"
                         (macro-function symbol))
              (info-line "It is a function"
                         (symbol-function symbol)))
          (doc-when 'function)
          (when (compiler-macro-function symbol)
            (info-line "It also names the compiler macro"
                       (compiler-macro-function symbol))
            (doc-when 'compiler-macro)))
        (format t "It has no function value.~%"))    
    ;; other info
    (when (find-package symbol)
      (info-line "It names the package"
                 (find-package symbol)))
    (when (find-class symbol nil)
      (info-line "It names the class" (find-class symbol)))
    (when (symbol-plist symbol)
      (info-line "Property list" (symbol-plist symbol)))))

and here's one way to generate a huge slime-repl buffer log:

(defun all-symbols-info ()
  (do-all-symbols (s)
    (symbol-info s)))

hth.

-- 
-Marco
Ring the bells that still can ring.
Forget your perfect offering.
There is a crack in everything.
That's how the light gets in.
     -Leonard Cohen