linuxcommand-linelispsbcl

How to run a file containing SBCL Lisp code on the command line


I just installed SBCL (on a Rapberry PI) using:

pi# apt install sbcl

I noticed that, unlike with clisp, putting:

#!/usr/bin/sbcl

at the top does not allow me to run a Lisp script file from the command line.

So my question is, once my Lisp code is written and stored in a file called test, what do I need to do - and how - (adding something to the file? Or compile it? Or ....) to be able to run it from the command line?

For a bit more details:

Here is what happens in the terminal:

pi@raspberrypi:~/SBCL $ cat test
#!/usr/bin/sbcl

(defun HI()
(let (vx 0)
(setf vx (+ (* 3 5) (mod 27 7)))
(format t "~a~%" vx)
))

(HI)

pi@raspberrypi:~/SBCL $ ls -l test 
  -rwxr-xr-x 1 pi pi 104 Dec  2 05:41 test
pi@raspberrypi:~/SBCL $ ./test 
This is SBCL 2.2.9.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
* 

Solution

  • The manual has a brief section about this.

    #!/usr/bin/sbcl --script
    
    (your Lisp code here)
    

    Of course, you'd have to know the term shebang to know to look for this.