The power of (save-image)


If you’re not already familiar with Lisp you could easily overlook a feature of uLisp that is virtually unique among programming systems: the ability to save the state of your environment with (save-image), and then restore it again at a later time with (load-image).

It’s not the same as reloading and recompiling a source file in other programming environments because (save-image) saves not only the currently-defined functions, but also the current state of all your global variables. This makes it very easy to write programs that accumulate data, and then save their current state without having to write routines to serialise the data to a file and read it back in again.

For a simple demonstration of the power of this feature see the example program Animals. This builds up a simple expert system based on input from the user, and the questions and answers are stored as a list in a global variable *data*:

(defvar *data* '("Does it live in the sea?" "a dolphin" "a horse"))

As you teach the program more animals the list grows to store the answers.

To save the program, together with the accumulated knowledge, you can simply do:


At a later time you can reload the program and the latest data with:



The way that (save-image) is implemented in uLisp on different platforms depends on the non-volatile memory features available:

  • On ATmega platforms EEPROM is provided, which is used.

  • The MSP430 platforms use either the flash program memory, or the non-volatile FRAM, to store the image.

  • The Adafruit M4 Express platforms use a separate serial DataFlash chip to store the image.

  • The STM32F103 platforms use flash program memory to emulate EEPROM for storing an image.

For full details of the size of image that you can store on each platform see Performance.


Hi David ,
First of all my best wishes to you and everybody on the forum !

I’m glad you mention the power of (save-image) , but is there a chance of getting it on the esp32 on sd-card instead of / or together with the eeprom ?
My program is too big to fit into the eeprom.

Btw : tomorrow I will post my results of showing images on a webserver using the sd-card.
I finally got it working :-)

Kind regards ,



Hi Ronny,

I’m planning to give you the choice of using the SD Card (if available) or EEPROM for save-image on the next release of uLisp. Hope to get that done within the next week or so.

Regards, David


Thank you very much !
Looking forward.



David ,

May I also suggest the define the sdcard cs pin to default to pin12 , instead of pin13 ?
Pin13 is connected to the onboard red led.
I spend some hours debugging sdcard problems because I was using the red led also in my project
and this of course gives problems when accessing the sdcard. :-(

Kind regards
Ronny Suy


Unique with todays languages commonly in use maybe. This was a central feature to Lisps and Smalltalk.


Hi David , Kaef

I was thinking this night , about autorun from sdcard.
Maybe to make it simpler you could use the flag in the C program
define sdcard …
if its false as in the default case then everything is on eeprom (save-image & load-image and autorun)
if the flag is true then loading and saving and autorun will be from sdcard.

This is a bit simpler but maybe it makes your programming a bit easier.

What do you and kaef think about this ?

Kind regards


Are there any other limitations of autorun for different platforms?

I tried load/save image on Arduino UNO, but I am not able to make the autorun feature to work. I have compiled the image with:

#define resetautorun

Or should this work on all platforms if no error is emitted?

Impressed by the project inte general. I have not used lisp before and this seems very attractive.

Best regards / Peter


It should work on all platforms. Here’s a simple demonstration:

  • Compile uLisp with #define resetautorun.

  • Define the following function:

    (defun bli ()
      (pinmode 13 t)
      (loop (digitalwrite 13 (not (digitalread 13))) (delay 1000)))
  • Save the image, and specify this function as the autorun function, with:

    (save-image 'bli)
  • Disconnect power to the Arduino Uno, and reconnect it.

The LED on pin 13 should start flashing.


Yes, sorry it works fine now. I must have mixed up versions of ulisp.ino where the resetautorun was still disabled.

Thanks for your clarification!


Great! Glad you got it working.