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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,73b34c20caa911d1 X-Google-Attributes: gid103376,public From: progers@acm.org Subject: Re: Math on dimensioned quantities Date: 1996/07/09 Message-ID: <4rui3u$h5b@uuneo.neosoft.com>#1/1 X-Deja-AN: 167452128 references: <9607091345.AA03915@most> organization: NeoSoft, Inc. reply-to: progers@acm.org newsgroups: comp.lang.ada Date: 1996-07-09T00:00:00+00:00 List-Id: In <9607091345.AA03915@most>, "W. Wesley Groleau (Wes)" writes: >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. You could make those undesirable operations abstract, which would make them uncallable.... > > >--------------------------------------------------------------------------- >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 >--------------------------------------------------------------------------- pat --------------- Patrick Rogers progers@acm.org