Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to explore a Common Lisp image

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

like image 558
Gradient Avatar asked Mar 01 '23 12:03

Gradient


1 Answers

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

like image 194
coredump Avatar answered Mar 08 '23 04:03

coredump