comp.lang.ada
 help / color / mirror / Atom feed
* Re: input/output exceptions
  2000-11-18  0:00     ` DuckE
@ 2000-11-18  0:00       ` Amal Kurian
  2000-11-19  0:00         ` Robert Dewar
  0 siblings, 1 reply; 7+ messages in thread
From: Amal Kurian @ 2000-11-18  0:00 UTC (permalink / raw)


While Robert Dewar pointed out, that 2.54 contains 2 and "junk" he should 
also have stated that since 2.54 is the last value to be read in, Ada 
ignores the junk and the program finishes while it couldn't ignore it if 
there is still something to be read in. Because a string consists of "junk" 
only ;) an exception is always raised.
To illustrate this, consider the modificated procedure:


with Ada.Integer_Text_IO, Ada.Float_Text_IO;
use Ada.Integer_Text_IO, Ada.Float_Text_IO;

procedure Test_Type_IO is

        First   : Integer       := 0;
        Second  : Float         := 0.0;
        

begin

        Get(First);
        Get(Second);
        
        Put(First);
        Put(Second);
        
end Test_Type_IO;


and the following values:


2.54
          2 5.40000E-01



Obviously the ignored "junk" from 2.54, that is 0.54, is a perfect float 
and is therefore assigned to 'Second'.

Kind regards,
Amal Kurian




DuckE wrote:

> 
> "Amal Kurian" <kurian.amal@t-online.de> wrote in message
> news:8v6ct8$jvj$07$1@news.t-online.com...
> > Robert Dewar wrote:
> >
> > > In article <3A2B4CF6@MailAndNews.com>,
> > >   Jean Cohen <jean.cohen@MailAndNews.com> wrote:
> > > 2.54
> > >
> > > I see an integer there, namely a 2, followed by junk, that's
> > > what Ada sees too!
> > >
> > >
> > > Sent via Deja.com http://www.deja.com/
> > > Before you buy.
> >
> > However while remaining quiet if the second number contains "junk"  Ada
> > screams loud if the same "junk" is contained in the first number. And I
> > think that's what the original poster was wondering about.
> >
> 
> I believe Robert answered the question.  If the first number entered is
> 2.54, an exception will occur when trying to read the second number.
> 
> SteveD
> 
> 
> 




^ permalink raw reply	[flat|nested] 7+ messages in thread

* input/output exceptions
@ 2000-11-18  0:00 Jean Cohen
  2000-11-18  0:00 ` Robert Dewar
  0 siblings, 1 reply; 7+ messages in thread
From: Jean Cohen @ 2000-11-18  0:00 UTC (permalink / raw)


Hi all,

I have a question regarding input/output exceptions. Suppose the following 
procedure:


with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;

procedure Test_Type_IO is

	First,	Second	: Integer := 0;

begin

	Get(First);
	Get(Second);

	Put(First);
	Put(Second);
	
end Test_Type_IO;


One should expect, that an input value which is not an integer (eg. a float) 
will raise an exception. However by executing the program I only get an 
exception [1] if the first value is not an integer. If the second one is not 
an integer, it seems, as if it is treated as one [2]:

3
2.54
          3          2

Why does the second value not raise an exception?

(The program is compiled by GNAT 3.13p on Debian GNU/Linux.)

Thank you,
Jean Cohen

(English is not my native language. I apologize for any misunderstandings 
that 
result of this reason.)


--------------------------

[1]	raised ADA.IO_EXCEPTIONS.DATA_ERROR : a-tiinio.adb:91 instantiated at 
a-inteio.ads:20

[2]	This is not the case if for instance strings are used - then the 
exceptions occur in every case.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: input/output exceptions
  2000-11-18  0:00 input/output exceptions Jean Cohen
@ 2000-11-18  0:00 ` Robert Dewar
  2000-11-18  0:00   ` Amal Kurian
  0 siblings, 1 reply; 7+ messages in thread
From: Robert Dewar @ 2000-11-18  0:00 UTC (permalink / raw)


In article <3A2B4CF6@MailAndNews.com>,
  Jean Cohen <jean.cohen@MailAndNews.com> wrote:
2.54

I see an integer there, namely a 2, followed by junk, that's
what Ada sees too!


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: input/output exceptions
  2000-11-18  0:00 ` Robert Dewar
@ 2000-11-18  0:00   ` Amal Kurian
  2000-11-18  0:00     ` DuckE
  0 siblings, 1 reply; 7+ messages in thread
From: Amal Kurian @ 2000-11-18  0:00 UTC (permalink / raw)


Robert Dewar wrote:

> In article <3A2B4CF6@MailAndNews.com>,
>   Jean Cohen <jean.cohen@MailAndNews.com> wrote:
> 2.54
> 
> I see an integer there, namely a 2, followed by junk, that's
> what Ada sees too!
> 
> 
> Sent via Deja.com http://www.deja.com/
> Before you buy.

However while remaining quiet if the second number contains "junk"  Ada 
screams loud if the same "junk" is contained in the first number. And I 
think that's what the original poster was wondering about.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: input/output exceptions
  2000-11-18  0:00   ` Amal Kurian
@ 2000-11-18  0:00     ` DuckE
  2000-11-18  0:00       ` Amal Kurian
  0 siblings, 1 reply; 7+ messages in thread
From: DuckE @ 2000-11-18  0:00 UTC (permalink / raw)



"Amal Kurian" <kurian.amal@t-online.de> wrote in message
news:8v6ct8$jvj$07$1@news.t-online.com...
> Robert Dewar wrote:
>
> > In article <3A2B4CF6@MailAndNews.com>,
> >   Jean Cohen <jean.cohen@MailAndNews.com> wrote:
> > 2.54
> >
> > I see an integer there, namely a 2, followed by junk, that's
> > what Ada sees too!
> >
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
>
> However while remaining quiet if the second number contains "junk"  Ada
> screams loud if the same "junk" is contained in the first number. And I
> think that's what the original poster was wondering about.
>

I believe Robert answered the question.  If the first number entered is
2.54, an exception will occur when trying to read the second number.

SteveD







^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: input/output exceptions
  2000-11-18  0:00       ` Amal Kurian
@ 2000-11-19  0:00         ` Robert Dewar
       [not found]           ` <3A28353B.40B4F990@ebox.tninet.se>
  0 siblings, 1 reply; 7+ messages in thread
From: Robert Dewar @ 2000-11-19  0:00 UTC (permalink / raw)


In article <8v6lfe$rc7$07$1@news.t-online.com>,
  Amal Kurian <kurian.amal@t-online.de> wrote:
> While Robert Dewar pointed out, that 2.54 contains 2 and
> "junk" he should  also have stated that since 2.54 is the last
> value to be read in, Ada  ignores the junk and the program
> finishes while it couldn't ignore it if
> there is still something to be read in. ]


I find the above formulation confusing, it implies there is
something special about Ada here.

In fact it's quite simple. If you have junk in the input,
and you do not read the junk, the program will not notice
there is junk.

I would expect that to be true of any language with a
reasonably straightforward view of sequential input.

The only thing that is special about Ada, and hence really
the only point that needs special comment is that if
you write 2.54 and read an integer, then only the 2 is
read.

I think it is very important for people to have the skills
to figure out the obvious consequences of rules like this.
Yes, I deliberately did not spell out those obvious
consequences, because I think it is a good idea for people
to think their way through things.

If you make the effort to think your way to the right
conclusion, given the basic axioms, and learn how to do
this, then you learn a really valuable lesson, and perhaps
you will be able to solve your next problem without asking
CLA. It is interesting to note that the original questioner
was not the one complaining about the lack of a full answer :-)


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: input/output exceptions
       [not found]             ` <90dp4s$45c$1@nnrp1.deja.com>
@ 2000-12-16 20:00               ` Stefan Skoglund
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Skoglund @ 2000-12-16 20:00 UTC (permalink / raw)


Robert Dewar wrote:
> > think) and parsing ends at EOL because EOL isn't part of the
> > domain of naturals !
> 
> EOL is not a character! You are thinking at too low a level.
EOL={CR|CRNL|NL}

> > 453 in first, starts parsing at 'a' !
> > BANG, 'a' isnt in the domain of natural numbers !! -> throw
> > exception !!
> 
> Yes, of course. What are the !! marks here for? This is
> of course what is expected. What's your point?

Someone didn't understand this pecularity of scanf and
Integer_IO.Get.
:-)




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2000-12-16 20:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-18  0:00 input/output exceptions Jean Cohen
2000-11-18  0:00 ` Robert Dewar
2000-11-18  0:00   ` Amal Kurian
2000-11-18  0:00     ` DuckE
2000-11-18  0:00       ` Amal Kurian
2000-11-19  0:00         ` Robert Dewar
     [not found]           ` <3A28353B.40B4F990@ebox.tninet.se>
     [not found]             ` <90dp4s$45c$1@nnrp1.deja.com>
2000-12-16 20:00               ` Stefan Skoglund

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