From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,66bb9de12d0a33f9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-12-05 08:02:59 PST Newsgroups: comp.lang.ada Path: bga.com!news.sprintlink.net!howland.reston.ans.net!usc!elroy.jpl.nasa.gov!netline-fddi.jpl.nasa.gov!nntp-server.caltech.edu!news.ridgecrest.ca.us!owens!do_while From: do_while@owens.ridgecrest.ca.us (Do-While Jones) Subject: Re: Dimensional Data Types Message-ID: Sender: usenet@ridgecrest.ca.us (Ridgenet Usenet admin) Organization: RidgeNet - SLIP/PPP Internet, Ridgecrest, CA. (619) 371-3501 References: <3briug$9ab@news-2.csn.net> Date: Mon, 5 Dec 1994 15:00:37 GMT Date: 1994-12-05T15:00:37+00:00 List-Id: 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 | +--------------------------------+