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.9 required=5.0 tests=BAYES_00 autolearn=ham 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-03 13:51:30 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!fu-berlin.de!uni-berlin.de!ppp-1-33.cvx4.telinco.NET!not-for-mail From: "Nick Roberts" Newsgroups: comp.lang.ada Subject: Dimensionality Checking (Ada 20XX) Date: Mon, 3 Dec 2001 21:13:38 -0000 Message-ID: <9ugs4v$8d7lj$1@ID-25716.news.dfncis.de> References: <3C0A5054.E74A82E7@worldnet.att.net> NNTP-Posting-Host: ppp-1-33.cvx4.telinco.net (212.1.148.33) X-Trace: fu-berlin.de 1007416288 8822451 212.1.148.33 (16 [25716]) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Xref: archiver1.google.com comp.lang.ada:17362 Date: 2001-12-03T21:13:38+00:00 List-Id: I really like this idea. I'd like to throw in a suggestion. I think probably the facility should only be applied to fixed-point types. All floating-point types would remain 'undimensioned' and there would be conversions and other operations between all floating-point, integer, and fixed-point types as usual (whose results would be undimensioned). There would be a new package, Ada.Physics, in which the following types and constants would be declared: type Physical_Dimension is (Mass, Distance, Time); type Dimensionality is array (Physical_Dimension) of Integer; Meter_Dimensionality: constant Dimensionality := (1,0,0); Metre_Dimensionality: constant Dimensionality := (1,0,0); Second_Dimensionality: constant Dimensionality := (0,0,1); -- etc. A programmer may then construct a package with unit declarations appropriate to a specific application domain, e.g.: package My_Physics is Foot_Dimensionality: constant Ada.Physics.Dimensionality := (1,0,0); generic type Feet is delta <>; type Meters is delta <>; function Generic_Feet_to_Meters (X: in Feet) return Meters; pragma Inline(Generic_Feet_to_Meters); -- etc. end; Then, in application code, the following could be used: -- TURD: Traditional Ultrasonic Ranging Device type TURD_Distance is delta 17.0/16200 range 1.0/12 .. 17.0; -- in feet pragma Dimensionality ( Type_Name => TURD_Distance, Dimensions => My_Physics.Foot_Dimensionality ); By supplying a Dimensionality pragma for the type T, dimension checking would then be applied to the "+", "-", "*", "/", and "**" operations of T as appropriate. The dimensionality of the result would be checked against: in an assignment, the target object; for an actual parameter, the corresponding formal. Of these operations, if either actual parameter (apart from the righthand one of "**") is undimensioned, no check would be applied (and the result is undimensioned). The checks would be entirely static. The pragma must occur before the type is frozen. The value of the Dimensions parameter must be static, and of type Ada.Physics.Dimensionality. These facilities could be defined in an optional annex. If a program which uses dimensionality checking were to be ported to a compiler which doesn't support it, the program should still compile and work as before, except only that the dimensionality checking would not be done. I would suggest that scaling and offset are done using existing Ada facilities. -- Nick Roberts