How to examine list of defined functions from Common Lisp REPL prompt

天涯浪子 提交于 2019-11-30 17:35:13

If you don't know what symbols you're looking for, but do know what packages you want to search, you can drastically reduce the amount of searching you have to do by only listing the symbols from those specific packages:

(defun get-all-symbols (&optional package)
  (let ((lst ())
        (package (find-package package)))
    (do-all-symbols (s lst)
      (when (fboundp s)
        (if package
            (when (eql (symbol-package s) package)
              (push s lst))
            (push s lst))))
    lst))

(get-all-symbols 'sb-thread) ; returns all the symbols in the SB-THREAD package

The line (get-all-symbols 'sb-thread) does just that.

If you have an idea about what type of symbols you're looking for, and want to take a guess at their names, you can do this

(apropos-list "mapc-") ; returns (SB-KERNEL:MAPC-MEMBER-TYPE-MEMBERS SB-PROFILE::MAPC-ON-NAMED-FUNS)
(apropos-list "map" 'cl) ; returns (MAP MAP-INTO MAPC MAPCAN MAPCAR MAPCON MAPHASH MAPL MAPLIST)

(apropos-list) returns all symbols whose name contains the string you pass in, and takes an optional package to search.

As far as figuring out what all those symbols do, well, try this: http://www.psg.com/~dlamkins/sl/chapter10.html

To list everything:

 (apropos "")

To list everything from a specific package add 'project-name:

(apropos "" 'quickproject)

To list all the packages (duh):

(list-all-packages)

To find functions exported from a particular package:

(loop for x being the external-symbol of "CL" when (fboundp x) collect x)
(let ((lst ()))                                                     
   (do-all-symbols (s lst)
     (when (fboundp s) (push s lst)))
   lst)

Pretty much taken as-is from here.

Maybe something like this:

(defun get-symbols-in-package (&optional (package *package*))
           (let ((lst ()))
             (do-symbols (s package)
               (push s lst))
             lst))

Use as (get-symbols-in-package) or (get-symbols-in-package 'foo) ...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!