Modula-2 Reloaded

A Modern Typesafe & Literate Programming Notation

Site Menu

Project

Specification

Implementation

Recommendations

Reference

Needs Updating

Work in Progress

Wastebasket

Wiki Manual

edit SideBar

One IO Module Per Pervasive Type

For each pervasive type the standard library provides one type specific I/O module. In order to facilitate the use of pervasive macros READ and WRITE, the type specific modules are named identical to their respective types.

The modules have to be imported directly or indirectly in order to use the pervasive macros READ and WRITE.

MODULE Example1;

FROM FileIO IMPORT File;

IMPORT CHAR; (* explicit import of CHAR's I/O module *)

VAR file : File; ch : CHAR;

BEGIN
    ...

    READ( file, ch );   (* equivalent to CHAR.Read( file, ch ); *)

    WRITE( file, ch );  (* equivalent to CHAR.Write( file, ch ); *)

END Example1.

Since it may be inconvenient to have to import each pervasive type's I/O module explicitly, the standard library should also provide a consolidated module that can serve as an import aggregator if desired. A module named PervasiveIO can be provided to serve this function.

MODULE Example2;

FROM FileIO IMPORT File;

IMPORT PervasiveIO; (* implicit import of all pervasive type I/O modules *)

VAR file : File; ch : CHAR;

BEGIN
    ...

    READ( file, ch );   (* equivalent to CHAR.Read( file, ch ); *)

    WRITE( file, ch );  (* equivalent to CHAR.Write( file, ch ); *)

END Example2.