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=-2.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,cc4f25d878383cc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-12-04 11:07:10 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!fr.usenet-edu.net!usenet-edu.net!enst!enst.fr!not-for-mail From: Wilhelm Spickermann Newsgroups: comp.lang.ada Subject: Unit handling (was: Another Idea for Ada 20XX) Date: Tue, 04 Dec 2001 20:02:36 +0100 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: References: <3C0A5054.E74A82E7@worldnet.att.net> <5ee5b646.0112021635.5bf7cd76@posting.google.com> <3C0AD67E.AE457644@worldnet.att.net> <3C0B7141.FEB5E5C1@BMW.de> Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: avanie.enst.fr 1007492829 90489 137.194.161.2 (4 Dec 2001 19:07:09 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Tue, 4 Dec 2001 19:07:09 +0000 (UTC) To: comp.lang.ada@ada.eu.org Return-Path: In-Reply-To: <3C0B7141.FEB5E5C1@BMW.de> X-Mailer: Mulberry/2.1.1 (Linux/x86) Content-Disposition: inline X-Sender: 0211750756-0001@t-dialin.net Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.6 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , List-Archive: Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:17393 Date: 2001-12-04T20:02:36+01:00 --On Monday, December 03, 2001 13:34:09 +0100 Dirk Dickmanns=20 wrote: ... > Besides the work of Lutz, I have: > http://users.erols.com/whitaker/iss_418.htm > http://www.dmitry-kazakov.de/ada/units.htm > May I add some of my ideas here? They could be realized as an=20 optional ASIS program checker or as a compiler component and=20 would not have any execution time penalty or require the tools=20 to be available to do the compilation. As unit consistency is a=20 program property, it=B4s not really necessary to have the tool = on=20 every platform and every site. The idea is to define the basic SI-Units as named numbers with=20 value 1.0 and using values like "5.7 * meter / second" in the=20 program. (The compiler can easily optimize such expressions.) A pragma for use by ASIS (or the compiler) defines which Units=20 are to be viewed as basic. Every variable, constant, parameter or named number will be=20 associated with a derived unit upon the first assignment seen,=20 by tracking the operations down to the basic units and all=20 following assignments will be required to lead to the same=20 result. Additionally all operations will be checked for=20 consistency. (As others have already pointed out, there are not=20 too many operations to be considered, as operations like taking=20 the logarithm of something can never be applied to something=20 having a unit) An additional ASIS-pragma can assign a derived unit to a=20 variable or parameter where the unit is not associated=20 implicitly by an initial or default value. A first sketch using SI as an example: package Units is -- The 7 SI units: Meter : constant :=3D 1.0; ... pragma Define_Unit (Meter, Kilogram, Second, Ampere, Kelvin, Candela, Mole); ... -- SI derived units: Newton : constant :=3D Meter * Kilogram / Second**2; ... -- SI accepted derived units: Liter : constant :=3D 1.0e-3 * Meter**3; ... end Units; (No special handling for the child units needed, they just=20 collect some definitions and try to convince programmers, that=20 that it=B4s a bad idea to define a factor "Billion" etc.) package Units.More is -- Defined (not experimentally determined) units. Foot : constant :=3D 0.3048 * Meter; Foot_US_Survey : constant :=3D Foot / 0.999998; ... -- experimentally determined units / constants Electron_Volt : constant :=3D 1.602_177_33e-19 * Joule; ... end Units.More; package Units.Factors is ... Kilo : constant :=3D 1.0E3; ... Billion_US_FR : constant :=3D 1.0E9; Billion_OTH : constant :=3D 1.0E12; ... Kilo_Binary : constant :=3D 2.0**10; ... end Units.Factors; I think this notation is readable and could be helpful even=20 without any tool to do the checks. It does not create any=20 runtime penalties. It should be possible to implement the=20 checker in ASIS or as an additional compiler component which may = be switched on or off. It=B4s not meant as a proposal for Ada=20 20XX, but if someone would like to view it as one: it would=20 only introduce conflicts in the two new pragma names. (It will however not be able to handle units like "decibels" or=20 "degrees celsius". I view these as pseudo units which only make=20 mathematical reasoning impossible. They should occur only in the = user interface as common expressions, but I=B4ve written that in = another mail.) Wilhelm