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:
(save-image)
At a later time you can reload the program and the latest data with:
(load-image)
Implementation
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.