8

I'm guessing this is not rocket science, but how can I run a compiled lisp file? I am using emacs and SLIME under Windows. From the SLIME menu it is straightforward to compile the file and, once it does, it spits out a wx64fsl in the same directory as my lisp source. How do I load/run this file? I've been running files by eval-ing whole blocks of code and I've been told that running the compiled version performs far better.

3 Answers 3

8

From the SLIME REPL:

  1. ,cd to change directories into the one with your lisp file
  2. (load (compile "filename.lisp"))

OR from the SLIME Menu:

SLIME > Compilation > Compile \ Load

So basically it was embarrassingly easy and there was even a menu option for it, I was just initially confused by the nomenclature. Hopefully this will help someone in the future.

3

Is your lisp implementation automatically compiling functions? SBCL on OS X does for me. If that's the case, I don't think you'll see any benefit from using the compiled files, other than saving compile time when loading the file.

Example taken from CLHS and tested on my setup at the REPL:

(defun f (x) x)
F
> 
(compiled-function-p #'f)
T
> 

In practice, I've always just used .lisp files. Never invested the time in using Make as a build tool to automatically compile lisp source code as it changes. I haven't seen any real-world benefits from using compiled fasls, at least on my setup, other than saving compile time (not speeding up run time).

And to save compile time, I use a technique where the majority of the packages/stable code are loaded up (automatically compiled) into the core file, so that compile time is minimal when I start with that core file and test some new code in a .lisp file.

1
  • 3
    The compilation model of the file compilation is slightly different. A file compiler can do more optimizations, may generate better messages in some cases and some errors can be detected early - during compilation. Often loading a source file is easy enough. I would recommend for larger pieces of code to use a system tool and load compiled code. Commented Apr 23, 2012 at 9:02
3

(LOAD "whatever") will usually load and compile whatever.lisp unless a compiled file is already present with the same name and an implementation specific extension. Those files are generated with (COMPILE-FILE "whatever.lisp") or in emacs with SLIME using the keys C-c C-k.

As Rainer recommends, you probably should be using ASDF to define your system, and most certainly quicklisp for managing dependencies and installing packages. There is also quickproject which I recommend for creating a project template. You can install it with quicklisp easily.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.