comp.lang.ada
 help / color / mirror / Atom feed
From: "Mark Lundquist" <mlundquist2@attbi.com>
Subject: Re: Incompatible type error handling
Date: Mon, 10 Dec 2001 23:03:10 GMT
Date: 2001-12-10T23:03:10+00:00	[thread overview]
Message-ID: <OabR7.4754$7y.13252@rwcrnsc54> (raw)
In-Reply-To: bf8dbe70.0112101352.20a3d257@posting.google.com


"Ben" <cptnben@gisco.net> wrote in message
news:bf8dbe70.0112101352.20a3d257@posting.google.com...
> Hi,
>
> I am new to Ada and the instruction book I found is not really helpful
> in explaining how to handle errors of unmatching types. For example,
> one of the sample problems the book has me do it a simple calculator
> made to work with real values. Say I programmed it to work only with
> integers, yet I enter  a real number. That will cause a problem,
> right?

Probably so... at least, the calculator is not going to do what the user has
in mind!

Actually, this issue has nothing to do with "types" or type mismatch.  You
are not really entering any kind of a number, you're entering a string.  The
process of getting some kind of number from that is not one of "conversion"
(as beginners often term it), but one of interpretation.  Ada defines some
elementary facilities that you can build on to do whatever interpretations
you need; but these facilities necessarily only know about one type, and
that is the type you are asking for.  So if you type "123.456" into your
calculator, Ada is not going to say "that's not an Integer, it's a Real
Number", any more than if you typed "cow" it would say "that's not an
Integer, it's an Animal".  I mean, "12.10" could be real number, or it could
be today's date, right?

In your integer calculator, "3.14159" is not a real number, it is nonsense,
and you'll have to program your calculator to recognize whatever you define
to be nonsense and handle that nonsense in whatever way you think a
calculator should handle it.

> Is the error handling automatic in Ada,

There's no error as far as Ada is concerned, only as far as your calculator
is concerned.

Hope this helps,
-- mark






  parent reply	other threads:[~2001-12-10 23:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-10 21:52 Incompatible type error handling Ben
2001-12-10 22:24 ` Mark Johnson
2001-12-10 23:03 ` Mark Lundquist [this message]
2001-12-11  3:19 ` Steve Doiel
replies disabled

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