[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Dec 3 19:53:16 1994 
Subject:new more sensible version of storedata 
From:"A.Sloman" 
Volume-ID:941204.01 

The present version of lib storedata, which was probably written in
the 1970s when Pop-11 ran only on a PDP11/40, is totally unsuitable for
modern Pop-11 systems where very large databases can be created.

The present version of storedata creates a single huge list expression
in the file and a command to assign it to database.

When the list is large, that causes excessively slow compilation because
when Pop-11 compiles the file, it first has to compile a procedure to
create the list then run the procedure.

In extreme cases it can even exceed the maximum permitted size for
procedures, producing this error message:

;;; MISHAP - PROCEDURE EXCEEDS MAXIMUM ALLOWABLE SIZE

(The maximum size probably ought to be documented in REF PROCEDURE, but
I could not find it anywhere.)

Anyhow, I have produced a new version, which seems to avoid all these
problems. Here it is. (John, Julian, feel free to make this replace
the system version.)

Revised "help" information is included. The original help file is no
longer accurate if you use this, though functionality of storedata is
not changed.

Aaron

/* --- The University of Birmingham 1994.  --------------------------------
 > Author:          Aaron Sloman, Dec  3 1994
 >  File:           $poplocal/local/auto/storedata.p
 >  Purpose:        storing database in a file
 >  Author:         Aaron Sloman
 >  Documentation:  HELP * storedata
 */


/*
This replaces LIB STOREDATA located in
    $usepop/pop/lib/database/storedata.p
which can cause compilation problems when the saved database is very
large.
=======================================================================

HELP STOREDATA                                     Aaron Sloman Dec 1994
LIB STOREDATA

storedata(<filename>)

                    SAVING A DATABASE IN A DISC FILE

If you wish to save the current state of your database (see the DATABASE
demo) in a file, then you will find the procedure STOREDATA useful.

It takes the name of a disc file as argument. For example, if you wish to
store the current database in a file called 'mydata.p', type:

    storedata("mydata");

or, equivalently:

    storedata('mydata.p');

later, e.g. in another programming session, you can restore the
contents of the database by typing:

    load mydata.p;

This can be used for writing programs which learn by interacting with
the user.  What they learn in one session can be stored in a file and
used in the next session.

*/

section;

;;; some text to go at the top of the file.
lconstant headerstring =
';;; FILE CREATED BY STOREDATA\
\
;;; Instruction to read in rest of file and create database\
[% until null(proglist) do\
     if hd(proglist) == "[" then listread()\
     else readitem()\
     endif\
    enduntil\
%] -> database;\
\
'
;


define storedata(filename);
    lvars filename;

    dlocal
        pop_pr_quotes = false,
        cucharout = discout(filename);

    ;;; Put code at top of file to read in rest of file
    pr(headerstring);

    ;;; Ensure strings are printed with quotes
    true -> pop_pr_quotes;
    ;;; print each item in the database separately, each starting on
    ;;; a new line
    for item in database do
        pr(item);       
        cucharout(`\n`);
    endfor;

    cucharout(termin);

enddefine;

endsection;