4

I called (load "code.lisp") with CCL, then accidentally deleted code.lisp. Is there any way for me to retrieve the source code? Does CCL have it in memory anywhere?

4

1 回答 1

7

这是一个非常特殊的功能。这里仅适用于Clozure CL。该代码在其他任何地方都不起作用。这在 CCL IDE 中对我有用。它检索某个包中的符号的源代码:internal:external对于从其他包继承的符号,它不会这样做(您通常会从包CL或中获得源代码CCL,这有点太多了)。

(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
于 2015-04-08T07:51:03.810 回答