comp.lang.ada
 help / color / mirror / Atom feed
* Ada'83 to Ada'95 Problem
@ 2001-03-01 11:43 dis00109
  2001-03-01 14:19 ` Marin David Condic
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: dis00109 @ 2001-03-01 11:43 UTC (permalink / raw)


I am trying to get a program to accept two integers as input by the user
(for a university project) however in the exception handling section of
my program it will not accept a float input as an error it merely
ignores everything after the decimal point. This would appear to be a
new feature in Ada'95, can anyone think of a way to solve this...PLEASE!




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

* Re: Ada'83 to Ada'95 Problem
  2001-03-01 11:43 Ada'83 to Ada'95 Problem dis00109
@ 2001-03-01 14:19 ` Marin David Condic
  2001-03-01 14:27 ` John English
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Marin David Condic @ 2001-03-01 14:19 UTC (permalink / raw)


Yes, this is a difference between Ada83 & Ada95. People complained that
Text_IO was too unforgiving when reading numeric values. One possible
solution is to read in the line as a string and scan the string for correct
input before reading the Integer from the string.

In real world software that requires keyboard input, you almost invariably
go to some form of parsing your own input characters because inevitably,
language-supplied features never do all the things you want them to do...

MDC


"dis00109" <dis00109@port.ac.uk> wrote in message
news:3A9E35F3.EE64F602@port.ac.uk...
> I am trying to get a program to accept two integers as input by the user
> (for a university project) however in the exception handling section of
> my program it will not accept a float input as an error it merely
> ignores everything after the decimal point. This would appear to be a
> new feature in Ada'95, can anyone think of a way to solve this...PLEASE!
>
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/






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

* Re: Ada'83 to Ada'95 Problem
  2001-03-01 11:43 Ada'83 to Ada'95 Problem dis00109
  2001-03-01 14:19 ` Marin David Condic
@ 2001-03-01 14:27 ` John English
  2001-03-01 18:23 ` Ted Dennison
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: John English @ 2001-03-01 14:27 UTC (permalink / raw)


dis00109 wrote:
> 
> I am trying to get a program to accept two integers as input by the user
> (for a university project) however in the exception handling section of
> my program it will not accept a float input as an error it merely
> ignores everything after the decimal point. This would appear to be a
> new feature in Ada'95, can anyone think of a way to solve this...PLEASE!

???

If you do this:
   Get(A); Get(B);
and you enter 3.14, you'll get a Data_Error at the point where "."
is read (the point where the point is read? ;-)  The first Get will
read an integer (3) and then stop at the first non-integer character
("."); the second Get will start at "." and go "ugh! that's not an
integer" and bail out with a Data_Error without reading anything.

If on the other hand you do this:
   Get(A); Skip_Line;
   Get(B); Skip_Line;
you'll get exactly the effect you've described; the first Get reads
an integer, and stops at the first non-integer character ("."), and
Skip_Line then throws the rest of that line away (".14" in this case).
The second Get will then read whatever is on the next line in the
same way.

Is this what you've done, perhaps?

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------



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

* RE: Ada'83 to Ada'95 Problem
@ 2001-03-01 17:39 Beard, Frank
  2001-03-05 13:51 ` John English
  0 siblings, 1 reply; 8+ messages in thread
From: Beard, Frank @ 2001-03-01 17:39 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

I think what she is talking about is:

  12  3.14

So,

  Get(A); Get(B);

yields "12" and "3" respectively.

She wants "3.14" to be an error for Get(B).

Frank

-----Original Message-----
From: John English [mailto:je@bton.ac.uk]
Sent: Thursday, March 01, 2001 9:28 AM
To: comp.lang.ada@ada.eu.org
Subject: Re: Ada'83 to Ada'95 Problem

???

Is this what you've done, perhaps?

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------
_______________________________________________
comp.lang.ada mailing list
comp.lang.ada@ada.eu.org
http://ada.eu.org/mailman/listinfo/comp.lang.ada




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

* Re: Ada'83 to Ada'95 Problem
  2001-03-01 11:43 Ada'83 to Ada'95 Problem dis00109
  2001-03-01 14:19 ` Marin David Condic
  2001-03-01 14:27 ` John English
@ 2001-03-01 18:23 ` Ted Dennison
  2001-03-01 19:29 ` Singlespeeder
  2001-03-02 16:03 ` Tucker Taft
  4 siblings, 0 replies; 8+ messages in thread
From: Ted Dennison @ 2001-03-01 18:23 UTC (permalink / raw)


In article <3A9E35F3.EE64F602@port.ac.uk>, dis00109 says...
>
>I am trying to get a program to accept two integers as input by the user
>(for a university project) however in the exception handling section of
>my program it will not accept a float input as an error it merely
>ignores everything after the decimal point. This would appear to be a
>new feature in Ada'95, can anyone think of a way to solve this...PLEASE!

Well, you may be able to do better by reading the characters into a string, then
using Integer'image (and perhaps Float'image). You also may find the routines in
Ada.Strings.Fixed useful.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



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

* Re: Ada'83 to Ada'95 Problem
  2001-03-01 11:43 Ada'83 to Ada'95 Problem dis00109
                   ` (2 preceding siblings ...)
  2001-03-01 18:23 ` Ted Dennison
@ 2001-03-01 19:29 ` Singlespeeder
  2001-03-02 16:03 ` Tucker Taft
  4 siblings, 0 replies; 8+ messages in thread
From: Singlespeeder @ 2001-03-01 19:29 UTC (permalink / raw)



"dis00109" <dis00109@port.ac.uk> wrote in message
news:3A9E35F3.EE64F602@port.ac.uk...
> I am trying to get a program to accept two integers as input by the user
> (for a university project) however in the exception handling section of
> my program it will not accept a float input as an error it merely
> ignores everything after the decimal point. This would appear to be a
> new feature in Ada'95, can anyone think of a way to solve this...PLEASE!
>

If you're using the Text_IO Get procedures make sure you're using Float_IO.

Be warned that on some compilers (in my experience DEC Ada 3.5-20) the
string really has to represent a float or it will raise an exception. GNAT
is more liberal in it's interpretation of the standard and will happily
return the integer part. You have to check the value of Last to see how much
of the string it converted.

Nick





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

* Re: Ada'83 to Ada'95 Problem
  2001-03-01 11:43 Ada'83 to Ada'95 Problem dis00109
                   ` (3 preceding siblings ...)
  2001-03-01 19:29 ` Singlespeeder
@ 2001-03-02 16:03 ` Tucker Taft
  4 siblings, 0 replies; 8+ messages in thread
From: Tucker Taft @ 2001-03-02 16:03 UTC (permalink / raw)


dis00109 wrote:
> 
> I am trying to get a program to accept two integers as input by the user
> (for a university project) however in the exception handling section of
> my program it will not accept a float input as an error it merely
> ignores everything after the decimal point. This would appear to be a
> new feature in Ada'95, can anyone think of a way to solve this...PLEASE!

There is no new feature of Ada 95 that would affect this behavior.
It is possible that the compiler has a bug, but without a copy
of the specific input and the specific exceptions raised, it
is pretty hard to tell.

The only new feature of Ada 95 affects using "get" for a floating point
value.  It sounds like you are using integer "get" and the semantics
for that are not changed in Ada 95.  The semantics for using "get"
on floats in Ada 95 are a true extension, in that anything that was
acceptable before is still accepted, but in addition, you can omit
a 0 before or after the decimal point if it is not a significant digit.

-- 
-Tucker Taft   stt@avercom.net   http://www.averstar.com/~stt/
Chief Technology Officer, AverCom Corporation (A Titan Company) 
Burlington, MA  USA (AverCom was formerly the Commercial Division of AverStar:
http://www.averstar.com/services/ebusiness_applications.html)



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

* Re: Ada'83 to Ada'95 Problem
  2001-03-01 17:39 Beard, Frank
@ 2001-03-05 13:51 ` John English
  0 siblings, 0 replies; 8+ messages in thread
From: John English @ 2001-03-05 13:51 UTC (permalink / raw)


"Beard, Frank" wrote:
> I think what she is talking about is:
> 
>   12  3.14
> 
> So,
> 
>   Get(A); Get(B);
> 
> yields "12" and "3" respectively.
> She wants "3.14" to be an error for Get(B).

Hmm, perhaps we need some clarification (including sample code) from
the original poster, then. IIRC, Ada 83 was no different to Ada 95
in this respect (it would read 3, and stop at the decimal point).

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------



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

end of thread, other threads:[~2001-03-05 13:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-01 11:43 Ada'83 to Ada'95 Problem dis00109
2001-03-01 14:19 ` Marin David Condic
2001-03-01 14:27 ` John English
2001-03-01 18:23 ` Ted Dennison
2001-03-01 19:29 ` Singlespeeder
2001-03-02 16:03 ` Tucker Taft
  -- strict thread matches above, loose matches on Subject: below --
2001-03-01 17:39 Beard, Frank
2001-03-05 13:51 ` John English

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