From: do_while@owens.ridgecrest.ca.us (Do-While Jones)
Subject: Re: Dimensional Data Types
Date: Mon, 5 Dec 1994 15:00:37 GMT
Date: 1994-12-05T15:00:37+00:00 [thread overview]
Message-ID: <D0CF11.BDB@ridgecrest.ca.us> (raw)
In-Reply-To: 3briug$9ab@news-2.csn.net
In article <3briug$9ab@news-2.csn.net> perez@oldcolo.com (Carlos Perez) writes:
>Do-While Jones (do_while@owens.ridgecrest.ca.us) wrote:
>
>: Since the USE clause makes the operators visible, I just write things like
>: "VELOCITY := DISTANCE / TIME;" and Ada does all the dimensional checking
>: for me. If I write "VELOCITY := DISTANCE / VOLTS;", I naturally get an
>: error message. Of course I can respond to the error message by doing
>: something really stupid, like "VELOCITY := DISTANCE / Seconds(VOLTS);", but
>: I am not that dumb yet.
>
>It appears to me that you have designed an idiot-resistant system
>(there is no such thing as idiot-proof ;-)
>
I regret including that paragraph. It caused more confusion than
enlightenment. I was trying to say that it is idiot-resistant but not
idiot-proof. I just didn't say it very well.
>I thought that your VOLTS was a private type and so you can't
type >cast VOLTS into SECONDS. You may need to have some functions whose
>sole purpose is to convert dimensional types into scalar (non-dim) types
>like Volts_To_Float and Float_To_Volts so you can define new and improved
>cross-dimensional operators such as "*".
>
>My point is that Ada won't permit a simple cast as you described, unless
>I missed something?
>
Yes, you did miss something. Volts and Seconds are private types. They
are DERIVED types that happened to be derived from a private type. So,
you can do a simple type cast. For example, this program compiles
without error:
with TIME_UNITS;
with ELECTRICAL_UNITS;
procedure Really_Stupid is
S : TIME_UNITS.Seconds;
V : ELECTRICAL_UNITS.Volts;
use ELECTRICAL_UNITS; -- for explicit type conversion
begin
V := Volts(S);
end Really_Stupid;
Which just goes to show that if you try really hard, Ada will let you
shoot yourself in the foot. But you have to try hard to do it, and it is
pretty obvious when you do.
>: Do-While Jones
>
>When-Others Perez
--
+--------------------------------+
| Know Ada |
| [Ada's Portrait] |
| Will Travel |
| wire do_while@ridgecrest.ca.us |
+--------------------------------+
prev parent reply other threads:[~1994-12-05 15:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1994-12-03 0:06 Dimensional Data Types Do-While Jones
1994-12-04 5:09 ` Carlos Perez
1994-12-05 1:39 ` Carlos Perez
1994-12-05 15:00 ` Do-While Jones [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