I am currently have a small program in Common Lisp, which I want to run as a shell script. I am using the SBCL and perfectly fine with this so will prefer to stay on this platform. 🙂
I am aware about the --script option and it works flawlessly except for (ql:quickload) form.
My program uses the CL-FAD, which loads through ql:quickload (I think I should mention that it is package-loading function from quicklisp). When script runs up to evaluating the
(ql:quickload :cl-fad)
form, it breaks with the next error:
package "QL" not found
Program is packed in the single source file, which has following header:
(defpackage :my-package
(:use :common-lisp)
(:export :my-main-method))
It is simple automation executable, so I decided (maybe erroneously) not to write any ASDF system. It exports single function which should be run without any arguments.
For this program I am currently trying to write the launcher script, and this is what I am staring at:
#!/usr/bin/sbcl --script
(load "my-program.lisp")
(in-package :my-package)
(my-main-method)
This three lines (not counting the shebang) is what I am want to automate. As I read in documentation, script with this shebang can be called as simple ./script.lisp, and it really does this… with the error described before.
What I need to add in the launcher for :cl-fad to load properly? Documentation states that with --script option SBCL doesn’t load any init file, so do I really need to copypaste the lines
#-quicklisp
(let ((quicklisp-init (merge-pathnames "systems/quicklisp/setup.lisp"
(user-homedir-pathname))))
(when (probe-file quicklisp-init)
(load quicklisp-init)))
(which ql:add-to-init-file adds to .sbclrc), to my launcher script?
Maybe I have some deep architectural flaw in my program setup?
And yes, when I enter the lines which I try to automate in REPL in the sbcl itself, program runs as expected.
Creating a dedicated version of core image is a good option. You may:
load
quicklispandsb-ext:save-lisp-and-diein a new image. You write a shell/bat script named, sayqlsbcl, like this:grab
clbuild2at http://gitorious.org/clbuild2 and runclbuild lisp. You’ll have to symlink clbuild to a binary directory in your path and tweak some scripts a bit if yourquicklispis not in the common place ~/quicklisp (https://gist.github.com/1485836) or if you useASDF2(https://gist.github.com/1621825). By doing so,clbuildcreate a new core withquicklisp,ASDFand anything you may add in conf.lisp. Now the shebang may look like this:The advantage of
clbuildis that you may easily create and manage core and quicklisp installation from shell forsbcl(by default) or any other modern CL likeccl64implementation. Mixing the two techniques (script andclbuild) will solve your problem.