0

I've been playing around with Quicklisp lately, and have this minor problem working with scripts with Shebangs.

Setup

I did the following:

  1. Downloaded quicklisp with curl https://beta.quicklisp.org/quicklisp.lisp -o /tmp/quicklisp.lisp
  2. Installed it with (quicklisp-quickstart:install) while having /tmp/quicklisp loaded in the environment.
  3. Added Quicklisp to init file using (ql:add-to-init-file)

Problem

For a script that needs Quicklisp (specifically ASDF), I can run it with sbcl --load ~/quicklisp/setup.lisp --script start.lisp just fine. However, when I run it as a standalone script with the Shebang /usr/bin/env sbcl --script, it fails with an error saying that it isn't able to find things like UIOP, etc. unless I place the below two lines in the script itself:

(load "~/quicklisp/setup.lisp")
(ql:quickload "asdf")

You can find my stupid experiment here, and the script in question here.

PS: Any pointers would be really helpful.

PPS: I'm sure it's a stupid mistake on my end, forgive me.

myTerminal
  • 1,596
  • 1
  • 14
  • 31
  • There's a very small limit on the number of arguments you can put in a shebang line. Like 2 or 3. – Barmar Jun 20 '22 at 22:58
  • I thought I should mention [this post](https://stackoverflow.com/questions/9229526/how-to-use-quicklisp-when-cl-program-is-invoked-as-a-shell-script?rq=1) here as it contains discussion on very similar lines. – myTerminal Jun 30 '22 at 01:47

2 Answers2

1

In that case you need:

(require :asdf)

TBH, I don't know exactly why. --script equals to --no-sysinit --no-userinit --disable-debugger --end-toplevel-options, so it's a lot we ignore. (thus loading quicklisp's setup.lisp seems required too, because it won't be loaded by your .sbclrc, which is where Quicklisp adds this little snippet)

It's a setting I have needed in other environments, such as a CI.

Ehvince
  • 17,274
  • 7
  • 58
  • 79
0

I would use roswell - which makes standalone scripts available which use Common Lisp code.

I described setting up roswell here. It is super easy. I describe there system-wide installation of roswell or also how to locally install roswell in ubuntu, mac and windows.

Or you could also directly lookup on roswell's site.

Using roswell would have the advantage that you can use any roswell-installable Common Lisp implementations, which are:

Candidates impls for installation are:
abcl-bin
allegro
ccl-bin
clasp-bin
clasp
clisp
cmu-bin
ecl
mkcl
sbcl-bin
sbcl
sbcl-source

not only sbcl alone.

And roswell allows scripts which are call-able directly from the shell while written in Common Lisp.

From inside roswell $ ros ... commands , quicklisp is available. So $ ros install xxx uses usually quicklisp to install xxx.

Using roswell, you can make any Common Lisp program callable from the bash by a single command - including your script - written in common lisp.

Look at e.g. here: https://roswell.github.io/Roswell-as-a-Scripting-Environment.html

Gwang-Jin Kim
  • 9,303
  • 17
  • 30