Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do image-based development in Common Lisp?

I am new to Common Lisp. This is how I develop programs in other languages, and also how I now develop programs in Common Lisp:

  1. Open a text editor (e.g. vim or emacs) to create/edit a text file.
  2. Write source code into the text file. (If unsure about the behavior of a snippet of code, and an REPL is available, then evaluate the snippet in the REPL, verify that the snippet evaluates as expected, and then go back to writing more code.)
  3. Save the text file.
  4. Ask the compiler/interpreter to load and run the source code in the text file. (e.g. sbcl --script myprog.lisp)
  5. Go to step 1 if needed.

This is the conventional write-compile-run development cycle for most programming languages. However, in the lisp world, I hear things like "interactive development" and "image-based development", and I feel that I am missing out on an important feature of Common Lisp. How do I do "image-based development" instead of "write-compile-run development"?

Can someone provide a step-by-step example of "image-based development" similar to how I described "write-compile-run development" above?

(Note: I am using SBCL)

like image 253
Flux Avatar asked Dec 14 '22 10:12

Flux


1 Answers

In typical Common Lisp implementations the runtime, the compiler, parts of the development environment and the program you are developing reside in the same program and share the same object space. The compiler is always available while you develop the program and the program can be incrementally developed. The development tools have access to all objects and can inspect their state. One can also undefine/remove, replace, enhance functionality from the running program.

Thus:

  • don't restart the program you are developing. Stay connected and update it. Even days, weeks, or months - if possible.
  • write code in such a way that the program can be replicated and built from scratch if necessary. Build it from time to time and fix any build problems.
  • once you use our program and there is an error -> fix the error within the program, while being able to inspect the full error state
  • creating a running program is either loading all code into a plain Lisp all the time or saving an executable image with the loaded code/data

Fixes to program bugs can also shipped to the user as compiled Lisp files, which gets loaded into the delivered program and update the code then.

like image 78
Rainer Joswig Avatar answered Feb 24 '23 17:02

Rainer Joswig