Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!yale!haveraaen-magne From: haveraaen-magne@CS.YALE.EDU (Magne Haveraaen) Newsgroups: comp.lang.pascal Subject: Re: I/O (was Re: Standard Pascal) Message-ID: <66532@yale-celray.yale.UUCP> Date: 15 Jul 89 15:50:03 GMT Sender: root@yale.UUCP Reply-To: haveraaen-magne@CS.YALE.EDU (Magne Haveraaen) Organization: Yale University Computer Science Dept, New Haven CT 06520-2158 Lines: 36 There are more ways to implement interactive I/O in Pascal than hitherto discussed on the net. A very simple and powerful scheme is as follows (and it was implemented in ND-Pascal from Norsk Data): Assume the input file of every program is initialized with the rest of the program call line. If there are no parameters, the input buffer will be initialized with an eoln (the return character you entered after the program name to start program execution). If some program parameters where given, these would comprise the first line, and would be readable with Pascal's read procedures. The scheme for writing a interactive dialogue would be (as already suggested on the net): : writeln('question 1'); readln; (*synchronize on first line*) read(answer); process(answer); writeln('question 2'); readln; (*synchronize on next line*) read(answer); process(answer); : In Sun Pascal (and other unix Pascals) one must omit the first "readln" in a dialogue, creating an unnecessary special case. This is aggravating if you e.g. want to have a general read-procedure that checks input and repeats the question if errors are made. Another advantage of this approach is that program parameters may now be read by Pascal's standard read procedures. This makes it very simple to read an integer parameter. And if you are so unixified that you have to look in an array for the program's parameters - well it is fairly easy creating a procedure that will initialize the global array by reading the initial line. Magne