The power of (save-image)


#1

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.


#2

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 ,

Ronny


#3

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


#4

Thank you very much !
Looking forward.

Ronny


#5

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


#6

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


#7

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
Ronny