Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get list of user created variables

I want to get a list of all variables that I have created in a lisp session. I think that this should be possible by looking at all symbols interned in common-lisp-user. But how can I get such a list?

like image 717
snowape Avatar asked Dec 03 '11 22:12

snowape


2 Answers

To get bound variables only from cl-user you iterate all bound symbols with do-symbols and exclude the symbols, that are imported from other packages:

(let ((external-symbols (mapcan (lambda (pkg)
                                  (let (rez)
                                    (do-symbols (s pkg rez)
                                      (push s rez))))
                                (package-use-list (find-package 'cl-user)))))
  (do-symbols (s 'cl-user)
    (when (and (boundp s)
               (not (member s external-symbols)))
      (print s))))
like image 57
Vsevolod Dyomkin Avatar answered Sep 29 '22 22:09

Vsevolod Dyomkin


You can use do-symbols to find the symbols in the common-lisp-user package.

See the CLHS entry for Macro DO-SYMBOLS, DO-EXTERNAL-SYMBOLS, DO-ALL-SYMBOLS

like image 45
Doug Currie Avatar answered Sep 29 '22 22:09

Doug Currie