3.3 Example

The fragment TextHashTable.bet defines a pattern TextHashTable whose instances are to be made persistent.

Program 1: TextHashTable.bet

ORIGIN '~beta/basiclib/betaenv';
INCLUDE '~beta/containers/hashTable';
INCLUDE '~beta/basiclib/texthash';

---lib: attributes---
TextHashTable: hashTable
  (# honey: @honeyman;
     init::< (# do honey.init #);
     element::< Text;
     rangeInitial:: (# do 300  -> value #);
     hashfunction::< (# do e[]->honey.hash -> value #);
  #);

The fragment fooprod.bet describes a program that creates a new persistent store and saves some persistent objects:

Program 2: fooprod.bet

ORIGIN '~beta/basiclib/betaenv';
INCLUDE '~beta/persistentstore/persistentstore';
INCLUDE 'TextHashTable';

--PROGRAM:descriptor--
(# PS: @persistentstore;
   H: ^TextHashTable;
do (* Create the persistent store *)
   PS.init;
   'myStore' -> PS.create; 

   (* Create a table of objects. *)
   &TextHashTable[] -> H[]; 
   H.init;
   'first' -> H.insert;
   'second' -> H.insert;
   'third' -> H.insert;

   (* Make the table a persistent root. *)
   (H[],'TextTable') -> PS.put;

   (* Checkpoint and close the store. *)
   PS.close
#)

The fragment foocons.bet describes a program that makes use of some persistent objects:

Program 3: foocons.bet

ORIGIN '~beta/basiclib/betaenv';
INCLUDE '~beta/persistentstore/persistentstore';
INCLUDE 'TextHashTable';
--PROGRAM:descriptor--
(# PS: @persistentstore;
   H: ^TextHashTable;   
   T: ^Text;
   do PS.init;
      'myStore'-> PS.openWrite;
      ('TextTable', TextHashTable## ) -> PS.get -> H[]; 
      'fourth' -> H.insert;
      H.scan  (# do current[] -> putLine #);
      PS.close
#)

Other example usages of the persistent store may be found in the directory BETALIB/demo/persistentstore. These demo programs, part of the Mjølner System, are listed below:

Example of usages of the OLD persistent store may be found in the directory BETALIB/demo/persistentstore/OLD. These demo programs, part of the Mjølner System, are listed below:


[2] Instances of patterns nested in the program pattern


Persistence in BETA - Reference Manual
© 1991-2002 Mjølner Informatics
[Modified: Monday October 23rd 2000 at 22:18]