HELP STOW Jocelyn Ireson-Paine November 1992 This module defines procedures for saving data to, and reading from, files. They are based on the same idea as the procedure 'datafile', described in HELP DATAFILE. To load the module, do lib stow; If you are using Eden, it will be loaded automatically. Introduction ------------ The idea is that you open a file by calling (for example): stow_to( filename ) -> c; where c is a variable. This makes c into a ``consumer'', that is a procedure which on each call takes its argument, and does something with it. You can then save arbitrary data items to this file by doing, e.g., c( a ); c( [% p, q, 1 %] ); c( retina ); Conceptually, each data item is stored on a new ``line'', and can be read back without getting mixed up with any of the others. When your file is complete, call c( termin ); to close it. You can then read back the data items, in order, by reversing this process: unstow_from( filename ) -> r; This makes 'r' into a ``repeater'' - that is a procedure that, on each call, returns the next item in sequence. Thus, these calls: r()=> r()=> r()=> will return the data items saved; when there are no more left, 'r' will return termin. Procedures exported ------------------- PUBLIC stow_to( filename ): Filename must be a string. stow_to returns a consumer, c. Every time c is called, it will save its argument to the named file. To close the file, call c(termin). Example: lvars keep; stow_to( 'mydata.' ) -> keep; keep(1); keep(2); keep( { [a b 1.2 3 {4} ] } ); keep(termin); PUBLIC unstow_from( filename ); unstow_from returns a repeater, r. Every time r is called, it will return the next piece of data in the file. If there is none left, it will return termin; sunsequent calls will provoke an error. Example: lvars get; unstow_from( 'mydata.' ) -> get; Calls of get() will then return the data written by keep.