2

My following code snippets will give SB-INT:SIMPLE-READER-PACKAGE-ERROR; I know it is because package "quicklisp-quickstart" is not defined yet while REPL reads the code; But the package IS defined in "quicklisp.lisp".

How can I make the following code work? Or How can I tell the common lisp reader this package will be defined in the dynamically loaded file?

* (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.
ll l
  • 149
  • 7
  • Are you having trouble installing the quicklisp ? If not, it'd be more informative to describe what you're trying to achieve and what steps you've taken. If yes, did you follow the https://www.quicklisp.org/beta/ step-by-step guide ? – cybevnm Dec 01 '16 at 09:45
  • 2
    Maybe `(eval (read-from-string "(quicklisp-quickstart:install)"))`. – coredump Dec 01 '16 at 11:25
  • NB Quicklisp's setup page shows an example of doing exactly this, and it'll offer to add it to your .sbclrc or equivalent startup file on installing… – BRPocock Dec 01 '16 at 15:30
  • 1
    I have no problem installing the quicklisp. I just want to load it, install it if not, during my application booting process. – ll l Dec 02 '16 at 06:16

1 Answers1

6

You can use FIND-SYMBOL to try and find the function, and call it with FUNCALL. Something like

(let* ((package (find-package :quicklisp-quickstart))
       (function (unless (null package)
                   (find-symbol (string '#:install)
                                package))))
  (if (null function)
      (error "Can't install...")
      (funcall function)))
jkiiski
  • 8,206
  • 2
  • 28
  • 44