Run Code From the Terminal

  • Open up a file browser and create a new file with a .lisp extension.

(defun hello ()
  "say hello to USER"
  (format t "hello ~a" (uiop:getenv "USER")))

(hello)

sbcl --load hello.lisp
  • The --load flag lets you see the result of the function call. We are not back at the terminal prompt, we are still in the Lisp image, so we are allowed to call the function again.
  • Then we have our string printed on standard output and NIL, which is the result of the function call that didn't return anything.
  • From this Lisp REPL you can eval, compile and run a Lisp file with the LOAD function. (load "hello.lisp") We get T for true here, because it tells us that the load function succeeded.

UIOP Manual, this is the standard library that is included with the Lisp installation.

sbcl --script hello.lisp
  • If you want to use this function, add (require :asdf) at the top of your file.
  • Recommended: use --load for development and --script when you want to run a program.
  • If you are using the --load flag, nothing prevents you from using (uiop:quit), to exit the Lisp process. It accepts an optional argument for the exit code.
  • If you use SBCL with a --script flag, you are going to pay a little startup penalty time.

3 Lisp Binaries

  • Compile your application and all its dependencies into a single executable
  • SBCL Binaries start-up blazingly fast
  • They weigh +-40MB with SBCL core compression
    • Or less with LispWorks, but this feature isn't in the free version.