comp.lang.ada
 help / color / mirror / Atom feed
From: "Nick Roberts" <nickroberts@adaos.worldonline.co.uk>
Subject: Dimensionality Checking (Ada 20XX)
Date: Mon, 3 Dec 2001 21:13:38 -0000
Date: 2001-12-03T21:13:38+00:00	[thread overview]
Message-ID: <9ugs4v$8d7lj$1@ID-25716.news.dfncis.de> (raw)
In-Reply-To: slrna0n5j7.kr.lutz@taranis.iks-jena.de

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






  reply	other threads:[~2001-12-03 21:13 UTC|newest]

Thread overview: 95+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-02 16:01 Another Idea for Ada 20XX James Rogers
2001-12-02 16:38 ` Preben Randhol
2001-12-02 22:26   ` James Rogers
2001-12-02 21:19 ` Patrick Hohmeyer
2001-12-02 21:26 ` Lutz Donnerhacke
2001-12-02 23:49   ` Patrick Hohmeyer
2001-12-03  6:06     ` Wilhelm Spickermann
2001-12-03  8:58     ` Lutz Donnerhacke
2001-12-03 13:40     ` Thomas Koenig
2001-12-03  0:21 ` Robert C. Leif, Ph.D.
2001-12-03  0:35 ` Robert Dewar
2001-12-03  1:33   ` James Rogers
2001-12-03 12:34     ` Dirk Dickmanns
2001-12-04 19:02       ` Unit handling (was: Another Idea for Ada 20XX) Wilhelm Spickermann
2001-12-03 14:56 ` Another Idea for Ada 20XX Mark Lundquist
2001-12-03 15:12   ` Lutz Donnerhacke
2001-12-03 21:13     ` Nick Roberts [this message]
2001-12-04 14:00       ` Dimensionality Checking (Ada 20XX) Dmitry A. Kazakov
2001-12-06 19:52         ` Britt Snodgrass
2001-12-06 20:55           ` Mark Lundquist
2001-12-06 22:38           ` Wes Groleau
2001-12-06 23:12             ` Mark Lundquist
2001-12-07 14:36               ` Wes Groleau
2001-12-07  9:37           ` Dmitry A. Kazakov
2001-12-07 22:51           ` Mark Lundquist
2001-12-03 17:00   ` Another Idea for Ada 20XX chris.danx
  -- strict thread matches above, loose matches on Subject: below --
2001-12-07  0:09 Dimensionality Checking (Ada 20XX) Snodgrass, Britt (NM75)
2001-12-07 16:15 ` Ian
2001-12-09 17:58   ` Nick Roberts
2001-12-09 22:58     ` Nick Roberts
2001-12-10  0:17     ` Mark Lundquist
2001-12-10  1:51       ` James Rogers
2001-12-10  3:33         ` Nick Roberts
2001-12-10 19:09           ` Nick Roberts
2001-12-11  8:20             ` Thomas Koenig
2001-12-11 15:37               ` Nick Roberts
2001-12-11 20:18                 ` Thomas Koenig
2001-12-12  0:58                   ` Mark Lundquist
2001-12-12  8:19                     ` Wilhelm Spickermann
2001-12-12 14:21                     ` Stephen Leake
2001-12-12 19:10                       ` Nick Roberts
2001-12-13 19:04                         ` Stephen Leake
2001-12-13 22:56                           ` Nick Roberts
2001-12-14  0:11                             ` Nick Roberts
2001-12-14 22:14                       ` Mark Lundquist
2001-12-15  1:30                         ` Nick Roberts
2001-12-10 20:22         ` Thomas Koenig
2001-12-10 17:21       ` Wes Groleau
2001-12-10 19:51         ` Mark Lundquist
2001-12-10 19:56           ` Wes Groleau
2001-12-10 20:37             ` Mark Lundquist
2001-12-10 18:56       ` Nick Roberts
2001-12-11 15:05         ` Wes Groleau
2001-12-11 16:39         ` Stephen Leake
2001-12-11 19:05           ` Nick Roberts
2001-12-11 22:50             ` Mark Johnson
2001-12-12  1:59               ` Nick Roberts
2001-12-11 23:01             ` Stephen Leake
2001-12-12  2:21               ` Nick Roberts
2001-12-12 14:16                 ` Stephen Leake
2001-12-13 19:52                   ` Nick Roberts
2001-12-13 22:22                     ` Nick Roberts
2001-12-14  6:40                       ` Robert C. Leif, Ph.D.
2001-12-14 17:30                       ` Stephen Leake
2001-12-14 17:38                     ` Stephen Leake
2001-12-11 22:45           ` Mark Lundquist
2001-12-12  1:42             ` Nick Roberts
2001-12-12 15:17               ` Mark Lundquist
2001-12-12 14:03             ` Stephen Leake
2001-12-12  9:35           ` Dmitry A. Kazakov
2001-12-12 14:26             ` Stephen Leake
2001-12-13 17:02               ` daniele andreatta
2001-12-13 19:06                 ` Stephen Leake
2001-12-14 10:16                 ` Dmitry A. Kazakov
2001-12-14 22:01                   ` Nick Roberts
2001-12-17 11:10                     ` Dmitry A. Kazakov
2001-12-17 12:16                       ` Thomas Koenig
2001-12-17 14:30                         ` Dmitry A. Kazakov
2001-12-27 17:18                         ` Steven Deller
2001-12-15  7:07                   ` Steven Deller
2001-12-17 12:31                     ` Dmitry A. Kazakov
2001-12-17 13:46                       ` Thomas Koenig
2001-12-17 15:00                         ` Dmitry A. Kazakov
2001-12-17 16:38                         ` Thomas Koenig
2001-12-17 21:07                       ` Britt Snodgrass
2001-12-20 13:44                         ` Dmitry A. Kazakov
2001-12-13 19:33         ` Mark Lundquist
2001-12-13 22:15           ` Nick Roberts
2001-12-14 20:20             ` Mark Lundquist
2001-12-10 23:31       ` Mark Lundquist
2001-12-10 13:57     ` Ian
2001-12-10 17:24       ` Wes Groleau
2001-12-10 20:38       ` Britt Snodgrass
2001-12-11 13:11 Mike Brenner
2001-12-11 17:03 ` Mark Lundquist
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox