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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,73b34c20caa911d1,start X-Google-Attributes: gid103376,public From: "W. Wesley Groleau (Wes)" Subject: Math on dimensioned quantities Date: 1996/07/09 Message-ID: <9607091345.AA03915@most>#1/1 X-Deja-AN: 167440960 sender: Ada programming language comments: To: info-ada%listserv.nodak.edu@emcee.com mailer: Elm [revision: 70.85] newsgroups: comp.lang.ada Date: 1996-07-09T00:00:00+00:00 List-Id: I once had to design and code capabilities for numeric types with dimensions. Did it two ways: for support code, each number was a record with its value and the units (enumerated). Efficiency was not a problem, but the lack of the 'usual' attributes was an irritation. The deliverable code used derived floats, not for the sake of attributes, but because of the (unfounded?) fear of size and time degradation. What turned out to be a nuisance here was redefining all the operators. A generic "operator with conversion factor" was easy enough though tedious for the legal operations such as "+"(L:feet;R:inch)return inch -> inch(L)*12+R Had to instantiate it in the spec in Ada-83, but now it can be instantiated in the body and then renamed. But it was a nuisance to have to declare Units_Mismatch : exception and redefine MANY multipliers and dividers to raise it. [For example "*"(L,R:inch)return inch] Some compilers will warn you "xxx exception will be raised at run-time" but it would be a nice language "feature" to extend type checking to this. I realize that for a compiler to know all the options, it would also have to know all the units, which is not feasible. But--compiler writers listening?--how about a pragma similar to pragma Disallow ( Operation => "*", For_Type => Inch ); If I'm repeating anyone (I don't get "Ada Letters") please forgive me. --------------------------------------------------------------------------- W. Wesley Groleau (Wes) Office: 219-429-4923 Magnavox - Mail Stop 10-40 Home: 219-471-7206 Fort Wayne, IN 46808 elm (Unix): wwgrol@pseserv3.fw.hac.com ---------------------------------------------------------------------------