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.1 required=5.0 tests=BAYES_00,FREEMAIL_FROM, FREEMAIL_REPLYTO_END_DIGIT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,cc4f25d878383cc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-12-02 12:56:40 PST From: Patrick Hohmeyer Subject: Re: Another Idea for Ada 20XX Newsgroups: comp.lang.ada Reply-To: pi3_1415926536@yahoo.ca References: <3C0A5054.E74A82E7@worldnet.att.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8Bit User-Agent: KNode/0.3.2 Message-ID: Date: Sun, 2 Dec 2001 16:19:08 -0500 NNTP-Posting-Host: 65.94.190.113 X-Complaints-To: abuse@sympatico.ca X-Trace: news20.bellglobal.com 1007326538 65.94.190.113 (Sun, 02 Dec 2001 15:55:38 EST) NNTP-Posting-Date: Sun, 02 Dec 2001 15:55:38 EST Organization: Bell Sympatico Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!torn!webster!nf1.bellglobal.com!nf2.bellglobal.com!news20.bellglobal.com.POSTED!not-for-mail Xref: archiver1.google.com comp.lang.ada:17313 Date: 2001-12-02T16:19:08-05:00 List-Id: James Rogers wrote : > In scientific terms a measurement is done in terms of some unit. > For instance, distance is in meters, microns, feet or furlongs. > Speed is then calculated as a distance per unit time. Acceleration > is the second derivative of speed. Acceleration is the second derivative of *distance*. ;-) > The advantage for the software developer is in the usage: > > Vehicle_Speed : Speed; > Track_Distance : Meters; > Lap_Time : Hours; > > Speed := Track_Distance / Lap_Time; > > This approach would allow the appropriate mixing of data types, which > is currently forbidden by Ada, in a meaningful and correct manner. > Hmm, this can very easly be achived with overloading of "/" : function "/" (Dist : Meters; Time : Hours) return Speed is --... And I have a huge problem with the name of the type Speed. Speed is not a unit, but an concept. Would be more interesting : type Distance is basic concept with basic unit Meters; type Time is basic concept with basic unit Seconds; type Speed is concept (Distance / Time); Vehicle_Speed : Speed; -- ok Track_Distance1 : Meters; -- ok Track_Distance2 : Meters := 12.5; -- ok Lap_Time1 : Time; -- ok Lap_Time2 : Time := Seconds(34.3); -- ok Lap_Time3 : Time := 34.3; -- 2 possibles reactions : -- 1. won't compile as the unit isn't specified !!! (my favor) -- 2. uses the basic unit for the concept (Seconds) -- (but generates a compiler warning) Vehicle_Speed := Track_Distance1 / Lap_Time1; --ok Internally a concept type would be something as record Value : Double; Unit : Unit_type; end record; Unit somehow describes how we can transform the value into a value in the basic units. (an access to a function?) and vice-versa. The great part are unit extentions : type Hours is Time unit 3600 Seconds; S : Seconds := 3954.3; H : Hours := S; And the compiler would automagicly put 3954.3 / 3600 into H. As would the cast Hours(S) return 3954.3 / 3600; Especially for Space programs between US and Europe this would be a *huge* benefit. Just declare : type Inchs is Distance unit x Meters; and the compiler will do all unit conversions for you. And of course : type Temperature is basic concept with basic unit Kelvin; type Celsius is Temperature unit 1 Kelvin + 273.15; And a non-basic concept : type Mass is basic concept with basic unit Kilogram; type Acceleration is concept Speed / Time; type Force is concept Mass * Acceleration; type Newton is Force unit 1 (Kilogram * Meters * Seconds**(-2)); (Note that : type Newton is Force unit 1 (Kilogram * Meters * Seconds**(-1) * Hours**(-1)); would also be syntaxly correct, you can mix 2 time units in a composed unit.) I think that this could be fun, but may be to complicated to implement and if you really need it, can already be done with a record and an access to fonction for the unit type, and a lot of overloaded functions. But what do you think ? -- Patrick Hohmeyer