From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=BAYES_20,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!watmath!watdragon!gvcormack From: gvcormack@watdragon.waterloo.edu (Gordon V. Cormack) Newsgroups: comp.lang.ada Subject: Re: END_ERROR on Text_Io.Get Message-ID: <12027@watdragon.waterloo.edu> Date: 4 Mar 89 19:51:33 GMT References: <2445@cc.helsinki.fi> Organization: U of Waterloo, Ontario List-Id: In article <2445@cc.helsinki.fi>, ylarotiala@cc.helsinki.fi writes: > > I wrote a piece of code: > > WHILE NOT Text_Io.End_Of_File(File) LOOP > Text_Io.Get(File,C); > ... > END LOOP; Get(char) ignores end-of-line, but End_of_file doesn't. I don't like the definition, but that's the way it is. Any function like End_of_file which trys to predict the future is destined to be strange. I'm not sure why Ada copied Pascal in this regard. In Pascal it was sort of necessary to compensate for the lack of a proper loop construct, but I see no excuse in Ada. It is necessary to get rid of newlines before END_OF_FILE will work properly in this case. Here is a sample program that echos its input (ignoring newlines). with text_io; use text_io; procedure eof is x: character; begin loop while end_of_line and then not end_of_file loop skip_line; -- get rid of newlines so END_OF_FILE will work end loop; exit when end_of_file; get(x); put(x); end loop; end eof; I personally prefer the following program, which is also correct: with text_io; use text_io; procedure eof is x: character; begin loop begin get(x); put(x); exception when end_error => exit; end; end loop; end eof; -- Gordon V. Cormack CS Dept, University of Waterloo, Canada N2L 3G1 gvcormack@waterloo.EDU gvcormack@uwaterloo.CA gvcormac@water.BITNET