Sometimes it is desirable to convert information from binary to text forms and then manipulate the resulting values. Conversely, when performing data entry (that is, reading data from the keyboard), it is usually better to perform the actual data entry in character format and then convert to internal values rather than converting the external data to internal values directly. The means of accomplishing this sort of specialised transput is provided by internal books.
Unfortunately, the QAD transput provided with the
a68toc compiler does not provide the usual
Algol 68 mechanism for internal books. However, a book consisting
of a single line can be established using the mem
channel
. Here is an example:
PROGRAM memch CONTEXT VOID USE standard BEGIN FILE mf; establish(mf,"",mem channel,1,1,36); FOR i TO 3 DO put(mf,i**3) OD; print((file buffer(mf)[:current pos(mf)], newline)); close(mf) END FINISH
When establishing a memory book using the mem channel
,
both the p
and the l
parameters should be
1
and the c
parameter should be positive
indicating the length of the line. All the transput procedures
mentioned may be used on memory books. The procedure file
buffer
yields the internal buffer of a file, but uses a mode we
have not yet met (see chapter 13: Standard Prelude). The
procedure current pos
gives the current position of its
REF FILE
parameter. For examples of files opened using
the mem channel
, see the example program lf
described in sections 12.3
to 12.3.3.