comp.lang.ada
 help / color / mirror / Atom feed
From: gvcormack@watdragon.waterloo.edu (Gordon V. Cormack)
Subject: Re: END_ERROR on Text_Io.Get
Date: 4 Mar 89 19:51:33 GMT	[thread overview]
Message-ID: <12027@watdragon.waterloo.edu> (raw)
In-Reply-To: 2445@cc.helsinki.fi

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

      reply	other threads:[~1989-03-04 19:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1989-03-01 21:56 END_ERROR on Text_Io.Get ylarotiala
1989-03-04 19:51 ` Gordon V. Cormack [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox