duane@cavell.UUCP (Duane Szafron) (09/08/84)
I think a discussion of i/o in modula-2 is an excellent idea. I also object to Wirth's idea of having only one stream for input and output at any one time. It causes unnecessary opening and closing of files. I prefer not to use the c-like printf and scanf however because I feel they they violate the spirit of good data abstraction. Ideally, I would like each object to have its own input and output operator. Since integers, cardinals, characters and reals are pre-defined in Modula-2, I would include i/o routines for these in one module. However, doesn't it seem reasonable to inclue i/o routines for user defined data-types (like string for example) with the other operators that operate on the data type? There are also several other definitions and capabilities that would make the i/o more usefull in practical situations: an "exists" function to see if a file exists, an "atEnd" function to see if the file pointer is at the end of a file, and "eol" and "eof" characters. (Yes I know that if you have an "atEnd" function then the "eof" character is superfluous, but in different situations, one wants to check for end of file in different ways.) I have included below a list of procedures and functions which I have implemented and use with Mike Powell's compiler. For the sake of brevity, I have included the names only. I think that the actions can be discerned from the names. open, close, exists, atEnd, readChar, writeChar, readCard, writeCard, readInt, writeInt and fail (returns true if the last readCard or readInt produced an error). Note that readReal and writeReal should be included but I haven't got around to it and I hardly ever use real numbers. In addition to the procedures and functions listed above, the type: File must be defined, as well as the variables: input (standard input), output (standard output), eof and eol. Well, what do the rest of you use? Duane Szafron Programming Languages Group Department of Computing Science University of Alberta