I am very new to LISP. I am using allegro-cl. I am having difficulty calling a function I have defined and loaded. I would like to know what are some ways I can browse the things I have defined, for instance listing all methods in a certain package, or listing just variables, or listing package names, etc.
-
similar: http://stackoverflow.com/questions/1511981/how-to-examine-list-of-defined-functions-from-common-lisp-repl-prompt – harschware Jan 24 '11 at 20:48
3 Answers
I'm not using Allegro CL, so I can only tell you about the tools CL itself provides for this. You might want to check what the Allegro CL IDE has to offer for this task.
You can get a list of all packages with the function LIST-ALL-PACKAGES. You could use it like this to print their names:
(dolist (p (list-all-packages)) (write-line (package-name p)))
CL packages are collections of symbols (i.e. names), not the objects associated with these names. You have to query the names in them further to see if there's a value and/or a function defined for that symbol. You can use DO-SYMBOLS to loop over all the symbols in a package. This would print all the symbols in the current package:
(do-symbols (s) (print s)
this only the functions:
(do-symbols (s) (when (fboundp s) (print s)))
and this only the functions whose home package is the current package:
(do-symbols (s)
(when (and (eq (symbol-package s) *package*)
(fboundp s))
(print s)))

- 6,556
- 21
- 27
-
very helpful thanks. How would I print the definition of a function? – harschware Jan 24 '11 at 18:44
-
those last two don't seem to limit to functions for the current package. Or at least, I see functions defined from all packages (which may be callable in the current scope). – harschware Jan 24 '11 at 18:49
-
There's no standard way to print the definition of a function. It might be possible if your implementation saves it to support debugging, but I think that's unlikely. But what should be possible to get is the source location. (if I understand SLIME's swank-allergro.lisp file correctly, Allegro should provide the `excl:find-source-file` function for that. – Rörd Jan 24 '11 at 19:07
-
Forget what I just wrote about imported symbols. A symbol's home package can be checked with SYMBOL-PACKAGE. See the new code example I've added to my answer. – Rörd Jan 24 '11 at 19:15
-
I don't know the mechanics of it, but it seems Allegro-CL has a source stepper (which perhaps means there is a way to view sources in other common lisp environments) http://bit.ly/elCS86 – harschware Jan 24 '11 at 20:28
If you remember a part of the name, you can always use APROPOS (possibly limited to a specific package) to find the full name.

- 20,782
- 4
- 54
- 70
I ran into the same problem. After reading documentation, I came to the opinion that there is no way to recall a definition typed into REPL.
To work around this problem, I always type into the editor window (Ctrl+N if not present). This way I can type definitions, edit them, etc. with great convenience. If I need to evaluate a definition, I press Ctrl+E for incremental evaluation (see other options in the Tools menu). I keep a listener window on the left and an editor window on the right to see inputs and outputs.
There is still a little problem which can even cause some bugs: if you forget to evaluate a definition after you have made changes to it, the old one remains in the REPL. Keep pressing Ctrl+E.
If you have several files open and want to locate a definition in one of source files, you can use Search>Apropos.

- 145
- 7