从CCL检索(加载)ed源代码?

时间:2015-04-08 04:04:49

标签: lisp common-lisp ccl

我用CCL调用(load "code.lisp"),然后意外删除了code.lisp。有没有办法让我检索源代码? CCL在内存中有没有它?

1 个答案:

答案 0 :(得分:7)

这是一个非常特殊的功能。此处仅适用于 Clozure CL 。该代码无法在其他任何地方使用。这在CCL IDE中适用于我。它检索特定包中:internal:external符号的源代码。它不会对从其他包继承的符号执行此操作(您通常会从包CLCCL获取源代码,这有点太多了。)

(defun retrieve-source-code (&optional (package *package*))
  (do-symbols (s package)
    (multiple-value-bind (symbol where)
                         (find-symbol (symbol-name s)
                                      package)
      (declare (ignore symbol))
      (when (member where '(:internal :external))
        (let ((ds (find-definition-sources s)))
          (when (and ds (listp ds))
            (loop for (nil sn) in ds
              for snt = (source-note-text sn)
              when snt do (progn
                            (terpri)
                            (princ snt)
                            (terpri)))))))))

如您所见,它可以自行检索(以及更多):

? (retrieve-source-code)

(defun retrieve-source-code (&optional (package *package*))
    (do-symbols (s package)
      (multiple-value-bind (symbol where)
                           (find-symbol (symbol-name s)
                                        package)
        (declare (ignore symbol))
        (when (member where '(:internal :external))
          (let ((ds (find-definition-sources s)))
            (when (and ds (listp ds))
              (loop for (nil sn) in ds
                for snt = (source-note-text sn)
                when snt do (progn
                              (terpri)
                              (princ snt)
                              (terpri)))))))))
NIL