How to explore a Common Lisp image
Asked Answered
G

2

7

Is there a way to explore the current state of a Common Lisp image (i.e. the loaded packages, available symbols, etc.)?

I know about the command (apropos "foo"), but I would like to see the current state of the whole image.

Is there such an explorer? I am using SBCL and SLIME (in Emacs).

Glans answered 2/7, 2021 at 7:9 Comment(0)
M
8

You can list all the existing packages with:

(list-all-packages)

For a given package, you can iterate over all its symbols or its external symbols:

(do-symbols (sym package)
  ...)

(do-external-symbols (sym package)
  ...)

You can also directly list all symbols in all packages:

(do-all-symbols (sym)
  ...)

When using Slime, inspecting a symbol with slime-inspect gives a summary of all things named after that symbol; for example, if I inspect 'number, the following is shown:

#<SYMBOL {5024C0CF}>
--------------------
Its name is: "NUMBER"
It is unbound.
It has no function value.
It is external to the package: COMMON-LISP [unintern]
Property list: NIL
It names the class NUMBER [remove]
It names a primitive type-specifier.

The NUMBER and COMMON-LISP texts above are also buttons, which you can click to visit the associated value. If you are only using SBCL, the same can be achieved by calling (find-class symbol nil) (the NIL indicates that no error should be reported if the symbol does not name a class), (symbol-plist symbol), etc.

There are some things which cannot be introspected according to the standard, like structs or the list of all user-defined types introduced with deftype (maybe other things). Depending on what you want to do, you may need to have a look at an implementation-specific way of doing this.


Thanks to David Hodge for pointing out the following:

A package called repl-utilities from Rob Warnock has a neat function called summary which shows each function, global variable with associated docstrings

Monandry answered 2/7, 2021 at 9:30 Comment(2)
A package called repl-utilities from Rob Warnock has a neat function called summary which shows each function, global variable with associated docstringsBlather
@DavidHodge Thank you, I added it to the answer so that it stands outMonandry
G
2

Here is a graphical, web explorer: https://github.com/lokedhs/docbrowser

Once started, it shows a first page with a list of all available packages loaded in the current image. Clicking on a package shows its functions and parameters, with their docstrings, and clicking on one shows its source code.

enter image description here

A similar one is livedoc, more recent and maybe more maintainted.

livedoc package

By the same proficient lisper, lisp-system-browser is a Slime extension (for Emacs then) that will act as a Smalltalk-ish browser: it will list all the available systems (think Quicklisp libraries) in a pane, when you click on a system it will list the available functions, macros and variables.

]3

Gentoo answered 13/7, 2021 at 16:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.