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
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 ***
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.
> 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
> 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
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.
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
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
···············@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.
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.
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