Confused about `` ql: quickload` 'and executable scripts in SBCL

I am trying to use Quicklisp packages in my executable script. A (trivial) working example:

#!/usr/bin/sbcl --script (eval-when (:compile-toplevel :load-toplevel :execute) (ql:quickload "lisp-unit")) ;as explained by another question (defpackage :test (:use :cl :lisp-unit)) (format t "This is a test.") 

After chmod entering a file with this code in it (called test.lisp ), I tried to execute it. However, I received the following error message:

 Unhandled SB-C::INPUT-ERROR-IN-LOAD in thread #<SB-THREAD:THREAD "main thread" RUNNING {1002C16923}>: READ error during LOAD: Package QL does not exist. Line: 4, Column: 15, File-Position: 95 Stream: #<SB-SYS:FD-STREAM for "file /home/koz/Documents/Programming/CL/trees/test.lisp" {1002C19A93}> Backtrace for: #<SB-THREAD:THREAD "main thread" RUNNING {1002C16923}> 0: ((LAMBDA NIL :IN SB-DEBUG::FUNCALL-WITH-DEBUG-IO-SYNTAX)) 1: (SB-IMPL::CALL-WITH-SANE-IO-SYNTAX #<CLOSURE (LAMBDA NIL :IN SB-DEBUG::FUNCALL-WITH-DEBUG-IO-SYNTAX) {1002C2498B}>) 2: (SB-IMPL::%WITH-STANDARD-IO-SYNTAX #<CLOSURE (LAMBDA NIL :IN SB-DEBUG::FUNCALL-WITH-DEBUG-IO-SYNTAX) {1002C2495B}>) 3: (PRINT-BACKTRACE :STREAM #<SB-SYS:FD-STREAM for "standard error" {1002C14CF3}> :START 0 :FROM :INTERRUPTED-FRAME :COUNT NIL :PRINT-THREAD T :PRINT-FRAME-SOURCE NIL :METHOD-FRAME-STYLE NIL) 4: (SB-DEBUG::DEBUGGER-DISABLED-HOOK #<SB-C::INPUT-ERROR-IN-LOAD {1002C1CB93}> #<unavailable argument>) 5: (SB-DEBUG::RUN-HOOK *INVOKE-DEBUGGER-HOOK* #<SB-C::INPUT-ERROR-IN-LOAD {1002C1CB93}>) 6: (INVOKE-DEBUGGER #<SB-C::INPUT-ERROR-IN-LOAD {1002C1CB93}>) 7: (ERROR #<SB-C::INPUT-ERROR-IN-LOAD {1002C1CB93}>) 8: (SB-C:COMPILER-ERROR SB-C::INPUT-ERROR-IN-LOAD :CONDITION #<SB-INT:SIMPLE-READER-PACKAGE-ERROR "Package ~A does not exist." {1002C1CAA3}> :STREAM #<SB-SYS:FD-STREAM for "file /home/koz/Documents/Programming/CL/trees/test.lisp" {1002C19A93}>) 9: (SB-C::READ-FOR-COMPILE-FILE #<SB-SYS:FD-STREAM for "file /home/koz/Documents/Programming/CL/trees/test.lisp" {1002C19A93}> 25 SB-C::INPUT-ERROR-IN-LOAD) 10: (SB-INT:LOAD-AS-SOURCE #<SB-SYS:FD-STREAM for "file /home/koz/Documents/Programming/CL/trees/test.lisp" {1002C19A93}> :VERBOSE NIL :PRINT NIL :CONTEXT "loading") 11: ((FLET SB-FASL::LOAD-STREAM :IN LOAD) #<SB-SYS:FD-STREAM for "file /home/koz/Documents/Programming/CL/trees/test.lisp" {1002C19A93}> NIL) 12: (LOAD #<SB-SYS:FD-STREAM for "file /home/koz/Documents/Programming/CL/trees/test.lisp" {1002C19A93}> :VERBOSE NIL :PRINT NIL :IF-DOES-NOT-EXIST T :EXTERNAL-FORMAT :DEFAULT) 13: ((FLET SB-IMPL::LOAD-SCRIPT :IN SB-IMPL::PROCESS-SCRIPT) #<SB-SYS:FD-STREAM for "file /home/koz/Documents/Programming/CL/trees/test.lisp" {1002C19A93}>) 14: ((FLET #:WITHOUT-INTERRUPTS-BODY-140 :IN SB-IMPL::PROCESS-SCRIPT)) 15: (SB-IMPL::PROCESS-SCRIPT "./test.lisp") 16: (SB-IMPL::TOPLEVEL-INIT) 17: ((FLET #:WITHOUT-INTERRUPTS-BODY-89 :IN SAVE-LISP-AND-DIE)) 18: ((LABELS SB-IMPL::RESTART-LISP :IN SAVE-LISP-AND-DIE)) unhandled condition in --disable-debugger mode, quitting 

I'm not sure what is going on here - if I try to do something similar from the top level (that is, run SBCL, load lisp-unit with ql:quickload , etc.), I don't get anything like this.

+8
common-lisp sbcl quicklisp
source share
2 answers

In SBCL, --script does not load your init files. If you want to use Quicklisp, you will need to download it. This usually means something like (load "~/quicklisp/setup.lisp") before using anything related to Quicklisp.

I do not think SBCL and Quicklisp are great for scripting tasks. When I write scripts, I usually do not expect them to extract material from the Internet, such as ql:quickload . Quicklisp is also quite verbose. SBCL FASL loading is rather slow. Taken together, this does not make for a very good scripting experience.

I very much prefer to load everything that I need, use it in a general Lisp session, and then call functions to do something. When I cannot use this (for example, to run files from cron or from Makefile), I often use buildapp to create executable files.

+10
source share

You must use cl-launch which is created for this purpose. You can enable Quicklisp by passing the -Q option. Your sample code would be something like this:

 #!/usr/bin/cl -Q -p lisp-unit (eval-when (:compile-toplevel :load-toplevel :execute) (ql:quickload "lisp-unit")) ;as explained by another question (defpackage :test (:use :cl :lisp-unit)) (defun main (argv) "Code goes here") 
+1
source share

All Articles