views:

222

answers:

3

Right now, everything I do manages to fit in a single source file, and a surprisingly small one at that. How do you decide how much and what to split off into separate files?

With Java, it's easy to decide what goes in one file (the decision is made for you already), but in Lisp I find I write many small functions that build on one another and it becomes hard to decide what, if anything should be split out. As I tackle larger projects in Lisp, it would be nice not to have to reinvent the wheel, but I can't find a lot of concrete info on the web about this.

Can you share some strategies for dealing with larger projects in Lisp, or point me to some resources that deal with this?

+4  A: 

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).

Daniel Dickison
I'm somewhat shocked - I know I've seen and skimmed that page in your link before, but had no idea what it was talking about at the time. It makes much more sense now in context - thanks!
Galghamon
It may help to study how small CL libraries set up their .asd files. Here's a simple little one that I wrote: http://common-lisp.net/project/cl-applescript/
Daniel Dickison
Thanks, seeing an example of a small package like this was really helpful!
Galghamon
+3  A: 

See "Making a small Common Lisp project" by Zach Beane.

huaiyuan
That's a good explanation / example of how to use ASDF, thanks
Galghamon
+7  A: 

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 or 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 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.

Rainer Joswig
Thanks - this is a useful list
Galghamon