Get list of user created variables

十年热恋 提交于 2019-12-10 17:11:13

问题


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?


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/8371708/get-list-of-user-created-variables

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!