.

Worlds


One of a series of tutorials about Scheme in general
and the Wraith Scheme interpreter in particular.

Copyright © 2011 Jay Reynolds Freeman, all rights reserved.
Personal Web Site: http://JayReynoldsFreeman.com
EMail: Jay_Reynolds_Freeman@mac.com.


Wraith Scheme has a mechanism to save the entire content of Scheme main memory, and some other things as well, in a special type of file, that may be reloaded later and reused. Many Lisp implementations provide such a mechanism: The process is traditionally called saving and reloading a world, and the saved files are traditionally called worlds.

This mechanism is an enhancement: It is not part of R5 Scheme. All of the procedures that deal with it have names that begin with "e::". Think "e" for "enhancement".

The icon for a Wraith Scheme world used to look like the following image, but it doesn't any longer. I include this picture for the benefit of those who may need to know about earlier versions of Wraith Scheme, and in the pious hope that I can some day restore its use.


Wraith Scheme World Icon

A saved world may be used as many times as you wish. Each time you load it, you will get back the state of Wraith Scheme when the world was created.

Saved worlds can be loaded only into the specific version and release of Wraith Scheme from which they were originally saved. Furthermore, it is possible that for some reason a saved world may not "fit" into a particular Wraith Scheme process; for example, the saved world may require more memory than the current Wraith Scheme process has, or it may have been created when more Wraith Scheme processes were running in parallel than are running when you try to use the world. If you encounter such a problem, change the Wraith Scheme Preferences to provide more of the missing resource, then restart Wraith Scheme.

You may load and reload any sequence of saved worlds into any running instance of Wraith Scheme, as long as each of them fits, but each time you load a world it will overwrite the entire content of the previous world. There is no way to "merge worlds".

It usually makes sense to save and load worlds only from top-level in Wraith Scheme, not from the middle of programs that are running: A saved world does not preserve the data that would be required to pick up in the middle of an executing program. Thus a saved world contains only a top-level environment: Once that environment is reloaded, you must evaluate an expression manually, or arrange that Wraith Scheme run a procedure automatically upon loading the world, to get things to start happening.

When a world is loaded, Wraith Scheme finds itself running at the top-level loop, even if the world was saved from within a program, or even if you called the procedure to load a world from within an executing program.

Saving a world does not cause Wraith Scheme to stop running. You can continue using a Wraith Scheme process after saving a world, just as if you had not saved the world in the first place.

You may load a Wraith Scheme world by using the "Load World" command from the Interpreter Menu, or by using the "e::load-world!" procedure. There are two forms of that procedure. This form simply causes Wraith Scheme to load the named world file.

This form causes Wraith Scheme to prompt you to type in the name of the world file in the dialog box, which is visible at the top of the Wraith Scheme window.

If you are using Wraith Scheme's ability to do parallel processing by running more than one Wraith Scheme process at the same time, only the MomCat process can load worlds. We haven't talked about parallel processing yet, but the MomCat will have "Wraith Scheme -- MomCat" in the title bar at the top of its main window.

You may save a Wraith Scheme world by using the "Save World" command from the Interpreter Menu, or by using the "e::save-world" procedure. It also has two forms, and works like the "e::load-world" procedure. The first form saves the world in the named file.

The second form also uses the Wraith Scheme dialog panel to prompt you for the name to use for the saved world.

Only the MomCat may save a world.


Let me be sure you understand: Loading a world overwrites everything in Wraith Scheme's memory! Any data that you have stored there will be gone.

In particular, if you load a world from within a Scheme program, the program will stop executing immediately after the load. If you use the "load" procedure (not "e::load-world!", I am talking about the ordinary "load" procedure for loading regular files) to load a file of Scheme code, and code in that file loads a world, then nothing more will be read from the file after the world load, because the "load" procedure itself will have stopped.


-- Jay Reynolds Freeman (Jay_Reynolds_Freeman@mac.com)


Wraith Face