2

我的以下代码片段将给出 SB-INT:SIMPLE-READER-PACKAGE-ERROR; 我知道这是因为 REPL 读取代码时尚未定义包“quicklisp-quickstart”;但是包是在“quicklisp.lisp”中定义的。

如何使以下代码工作?或者我如何告诉普通的 lisp 阅读器这个包将在动态加载的文件中定义?

* (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.
4

1 回答 1

6

您可以使用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)))
于 2016-12-01T06:52:30.960 回答