common lisp中如何做动态加载(Load)
How to do dynamic load (Load) in common lisp
我的以下代码片段将给出 SB-INT:SIMPLE-READER-PACKAGE-ERROR;
我知道这是因为 REPL 读取代码时包 "quicklisp-quickstart" 尚未定义;但是包是在 "quicklisp.lisp".
中定义的
我怎样才能使下面的代码工作?
或者我如何告诉普通的 lisp reader 这个包将在动态加载的文件中定义?
* (let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp"
(user-homedir-pathname))))
(if (probe-file quicklisp-init)
(load quicklisp-init)
(progn
(load "quicklisp.lisp")
(quicklisp-quickstart:install))))
debugger invoked on a SB-INT:SIMPLE-READER-PACKAGE-ERROR in thread
#<THREAD "main thread" RUNNING {100299C6A3}>:
Package QUICKLISP-QUICKSTART does not exist.
Stream: #<SYNONYM-STREAM :SYMBOL SB-SYS:*STDIN* {100017F893}>
Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit debugger, returning to top level.
您可以使用FIND-SYMBOL
尝试找到函数,然后使用FUNCALL
调用它。像
(let* ((package (find-package :quicklisp-quickstart))
(function (unless (null package)
(find-symbol (string '#:install)
package))))
(if (null function)
(error "Can't install...")
(funcall function)))
我的以下代码片段将给出 SB-INT:SIMPLE-READER-PACKAGE-ERROR; 我知道这是因为 REPL 读取代码时包 "quicklisp-quickstart" 尚未定义;但是包是在 "quicklisp.lisp".
中定义的我怎样才能使下面的代码工作? 或者我如何告诉普通的 lisp reader 这个包将在动态加载的文件中定义?
* (let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp"
(user-homedir-pathname))))
(if (probe-file quicklisp-init)
(load quicklisp-init)
(progn
(load "quicklisp.lisp")
(quicklisp-quickstart:install))))
debugger invoked on a SB-INT:SIMPLE-READER-PACKAGE-ERROR in thread
#<THREAD "main thread" RUNNING {100299C6A3}>:
Package QUICKLISP-QUICKSTART does not exist.
Stream: #<SYNONYM-STREAM :SYMBOL SB-SYS:*STDIN* {100017F893}>
Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit debugger, returning to top level.
您可以使用FIND-SYMBOL
尝试找到函数,然后使用FUNCALL
调用它。像
(let* ((package (find-package :quicklisp-quickstart))
(function (unless (null package)
(find-symbol (string '#:install)
package))))
(if (null function)
(error "Can't install...")
(funcall function)))