I'm having some difficulty finding an answer to this, so maybe it isn't possible. I'd like the flexibility of being able to load/compile a lisp file from a command line, i.e. not inside emacs, and then also run one of the lisp functions in that file also from the command line. This is no doubt implementation specific feature, so any pointers on an implementation that offers this (or perhaps it is fairly standard, I don't know). I'm using SBCL and like it, so it would be great if that could do this.
Also I'm using Mac OSX and Terminal.
As other people have shown, pretty much all implementations have some of running Lisp code via the terminal. There are also some wrappers that provide a common interface to many implementations: CIM and cl-launch.
The following is a paste from the first google result:
I just tested it on my arch linux terminal and you can do the following:
$ clisp myprogram.lisp
This will run the program right in the terminal. If you want to compile it to run later, see the above bit.
The SBCL manual describes three useful options
Given a file
test.lisp
with contentswe can do this with SBCL:
The
(progn ... (sb-ext:quit))
makes sure that the program ends after executing(hello-world)
. Otherwise you get dropped into the SBCL prompt. Since code is compiled automatically in SBCL, the function that you're running is already compiled by the time(hello-world)
is run. If you've compiled the file in advance, you can pass the compiled file to--load
. E.g.,In fact,given the equivalence of
--load
to--eval (load "filename")
, you can just use the base of the file name, and if there's a compiled version, then SBCL should load that, and if there's not, then SBCL will load the source file and you'll get compiled code that way. E.g., in the following, we use just--load test
: