Modula-2 input/output procedure using polymorphic and open-ended data type extensions (abstract only)

The Modula-2 language does not include special statements or standard procedures for handling input and output as in other languages. By extending Modula-2 to include a polymorphic structure, called a variant data type(1), and allowing open-ended structures, it is possible to define procedures that have a function and syntax similar to the I/O statements and procedures of other languages. The variant data type consists of a tag field followed by several options, each containing only one field (unless a structure definition is used). In an assignment operation, the tag field is implicitly adjusted to indicate the data type of the item assigned to the variant typed object. A variable of variant type is considered to be assignment compatible with another value if either both are exactly the same type or if one of the options of the variant type is compatible with the value being assigned to it. For open-ended data structures, the concept of an open array is generalized to allow stack and dynamically allocated open arrays to be defined which allows them to be sized at run-time. The open array concept is extended to procedures allowing them to have open parameter lists which can accept a variable number of arguments when called. These concepts can further be used to eliminate the need for several other standard procedures in the language definition.The variant type and open parameter lists are used in the definition module given below to define a set of Pascal-like input/output procedures. Two variant data types are defined, INVAR for the READ procedures and OUTVAR for the WRITE procedures. The options in these data types allow passing of the basic types as well as structured types using the ARRAY OF WORD option. This option must be specified last in the list since it is type compatible with all types. The word VAR in type INVAR indicates that a field is accessed by reference.The data type FILE is a hidden type for use in defining file variables. The parameter lists for the input and output procedures allow the file variable to occur anyplace in the argument list. It can even occur several times or not at all in a single argument list or several different file variables can appear. The read and write procedures can be programmed to not accept a file variable after the first argument. Violations cannot be detected at compilation time and would have to be flagged as run-time errors. Instead of adding these restrictions, they can be allowed as variations from standard Pascal. The result is that a single read or write statement can act like several statements accessing different files.The file variables INPUT and OUTPUT are defined for use in accessing a terminal's keyboard and screen respectively, as in Pascal. Importing these file variables is only necessary if they are to be explicitly used otherwise they can be programmed as the defaults in the implementation module. The implementation module cannot know whether INPUT and OUTPUT have actually been important by another module or whether they are used as the default file variables so it must initialize them upon program startup.