我打电话(load "code.lisp")给CCL,然后意外删除了code.lisp.有没有办法让我检索源代码?CCL在内存中有没有它?
这是一个非常特殊的功能.这里仅适用于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)))))))))
Run Code Online (Sandbox Code Playgroud)
如您所见,它可以检索自己(以及更多):
? (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
Run Code Online (Sandbox Code Playgroud)