Pergunta

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.

Foi útil?

Solução

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

Outras dicas

If you remember a part of the name, you can always use APROPOS (possibly limited to a specific package) to find the full name.

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top