File types

Description

File types define collections of values that usually have the same type (called the file type's component type). File type component types can not be file types or types which contain file types. There is a special file type named binary which has no component type, and can define collections of values with different types.

The collection of values defined by a file type is usually just called a file for short. Files are stored on external storage devices, unlike values of other types which are stored in memory. The main advantage of files over values of other types is that, files can persist after the program that created them is terminated. The main disadvantage of files compared to values of other types is that, accessing files is usually much slower than accessing values of other types (this is because accessing external storage devices is usually much slower than accessing memory).

In theory files can store an unlimited number of values, however in practice the number of values stored in files is limited by the amount of available space on the external storage devices used to store the files. The operating system controlling the external storage devices will also have a limit on the size of files, but this limit is usually very large and does not affect most programs.

You can add to, and change the values of, a file using the following built-in procedures:

You can retrieve values from a file using the following built-in procedures:

Before you can add values to, change the existing values of, or retrieve values from, a file you have to associate it with a file variable. NOTE: This process is sometimes referred to as opening the file, or opening the file variable. See append, open, reset, and rewrite.

When you have finished adding values to, changing the existing values of, or retrieving values from, a file you should disassociate the file from the file variable. NOTE: This process is sometimes referred to as closing the file. See close. It is not necessary to close files if the program is about to terminate.

Although files are stored on external storage devices, the operating system will usually temporarily store portions of open files in memory to speed up access. However this means that changes made to files can be lost if the program crashes. If you want to make sure that the changes made to a file are stored on an external storage device, then use the built-in procedure flush.

Example

Here are some examples of file types

   file of integer;
   file of char;

Syntax

The syntax for defining new file types is given below:

(NOTE: for clarity some parts of the syntax are omitted, see Irie Pascal Grammar for the full syntax):

   file-type = 'file' 'of' component-type

   component-type = type-denoter

   domain-type = type-identifier

   new-ordinal-type = enumerated-type | subrange-type

   new-pointer-type = '^' domain-type | '@' domain-type

   new-structured-type =
      [ 'packed' ] array-type |
      [ 'packed' ] record-type |
      [ 'packed' ] set-type |
      [ 'packed' ] file-type |
      [ 'packed' ] list-type |
                         object-type |
                         string-type

   new-type = new-ordinal-type | new-structured-type | new-pointer-type

   type-denoter = type-identifier | new-type

   type-identifier = identifier