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

5

16

I'm evaluating/testing a browser based application presumably written in common lisp. Apart from the browser based interface, the software provides a 'Listener' window with a 'CL-User >' REPL prompt.

I wish to examine the list of functions, symbols, and packages from the REPL prompt. So that I could co-relate the frontend functionality with what is exposed via the REPL.

Google search is futile for me as it leads to tutorials and resources that teaches lisp step-by-step.

Any hints, pointers on examining the state via REPL will be much appreciated.

Crackup answered 2/10, 2009 at 21:56 Comment(0)
B
12

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

Bodine answered 3/10, 2009 at 0:24 Comment(1)
Aha (apropos-list) what the doctor ordered. Thanks for the link too.Crackup
A
10

To list everything:

 (apropos "")

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

(apropos "" 'quickproject)
Attested answered 31/10, 2012 at 6:41 Comment(0)
F
7

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)
Faythe answered 2/10, 2009 at 22:55 Comment(1)
Easy to understand one liner for the 'procedurally spoiled'. Thanks.Crackup
M
4
(let ((lst ()))                                                     
   (do-all-symbols (s lst)
     (when (fboundp s) (push s lst)))
   lst)

Pretty much taken as-is from here.

Mabelmabelle answered 2/10, 2009 at 22:34 Comment(1)
I did land on the page you suggested via google search prior to posting here. But was not able to figure out the above on my own. Thanks for the crystal clear code.Crackup
O
0

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) ...

Octet answered 12/8, 2017 at 4:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.