Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!psuvax1!schwartz From: schwartz@shire.cs.psu.edu (Scott Schwartz) Newsgroups: comp.lang.pascal Subject: I/O (was Re: Standard Pascal) Message-ID: Date: 14 Jul 89 03:15:01 GMT References: <20239@adm.BRL.MIL> Sender: news@psuvax1.cs.psu.edu Organization: Pennsylvania State University, computer science Lines: 40 In-reply-to: RDK%vm.temple.edu@cunyvm.cuny.edu's message of 13 Jul 89 Robert Keiser writes: | WRITELN('WHAT IS YOUR NAME'); | READLN; (* FORCE A GET *) | I := 1; | WHILE NOT EOLN DO | BEGIN | READ(NAME[I]); | I := I + 1; | END; | I mean, it would seem that to follow the way Pascal is supposed to | work with the "look ahead" buffer it would require something special | to avoid the above example. A pure implementation of Pascal I/O would have the program block just after it began executing while it waited for the INPUT buffer to get filled. The most common technique for making interactive I/O work sensibly is called "lazy I/O", and arranges not to block for input until necessary. In your example, the "READLN (* FORCE A GET *)" doesn't seem to be what you really want to do, since it could potentially discard valid input in addition to filling the buffer. Beyond that, I would have expected the EOLN to force the (buffer filling) GET, since that's when you actually require the data. Similarly, if you had some thing like "foo := input^" as the first use of "input", the buffer would be filled at that point. (Of course, the runtime system should only do the inplicit GET once, to initialize the input stream, not each time you do that statement. Some pascal to C translators screw this up.) A quick test with Sun's Pascal compiler shows that omitting the READLN results in a working program, as expected. -- Scott Schwartz