How do I go about splitting Lisp code into multiple source files?

See "Making a small Common Lisp project" by Zach Beane. He has an updated post at Making a small Lisp project with quickproject and Quicklisp


If you're using Common Lisp, ASDF is a popular way to specify systems. It handles load order dependencies between your source files (and a whole lot more).


When you start writing a Lisp program then it might be useful to start with a single file. Once the code gets too large (whatever that is) you can split it up. When you are approaching something that needs organization, then you should invest some work into it.

A few hints:

  • There are a few tools to manage source file dependencies and provide actions like compile, load, compile-and-load and others. ASDF is one, but there are also others.

  • You need one file to describe the dependencies. Name it so that it can be recognized.

  • You might need a file to define one or more packages.

  • You might need put implementation specific functionalities in their own files.

  • move larger amounts of configuration data to their own files

  • general utilities should be in another file

  • macros should be defined before used. Other files depend on this file and should be recompiled automatically if the macro definition is changed.

  • group functionality together into a file if it is logically connected. In a drawing program: all drawing functions, all user interface commands, saving data to files, printing, ...

  • don't care too much about the file size. Lisp source files can be large. Sometimes 100k.

  • moving around in the files is supported by the development environment. M-. on a symbol finds its source.

  • make sure that you can reload a file, without the need to restart the whole Lisp.

  • Common Lisp provides LOAD and COMPILE-FILE as functions. You can use these functions in your own files.