comp.lang.ada
 help / color / mirror / Atom feed
* RE: Dimensionality Checking (Ada 20XX)
@ 2001-12-07  0:09 Snodgrass, Britt (NM75)
  2001-12-07 16:15 ` Ian
  0 siblings, 1 reply; 78+ messages in thread
From: Snodgrass, Britt (NM75) @ 2001-12-07  0:09 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'



> -----Original Message-----
> From: Wes Groleau [mailto:wgroleau@usa.com]
> Sent: Thursday, December 06, 2001 3:39 PM
> To: comp.lang.ada@ada.eu.org
> Subject: Re: Dimensionality Checking (Ada 20XX)
> 
> Britt Snodgrass wrote:
> > (dimensionality) in Ada code would be most naturally implemented as
> > attributes of objects or types.  The units of an object or type would
> > be specified with a representation clause.  If unspecified, the unit
> 
> I think this is a very good idea.  But now to nitpick:
> 
> >    Accel : Magnitude;
> >    for Accel'Unit use
> >      ISO_Metric_Units.Meter / ISO_Metric_Units.Second**2;
> 
> In some cases, might there be multiple ways to describe
> the units?   Speed is Acceleration * Time but it is also
> Distance / Time.

Yes, but the compiler would resolve both of these to a canonical form such
as Distance_Unit**(1)*Time_Unit**(-1) and know that they both represent the
same composite unit.

I am also thinking that unit conversions could be accomplished using syntax
similar to the following example:

      type Magnitude is digits 15;

      Accel_FPS2 : Magnitude;
      for Accel_FPS2'Unit use
        Goofy_Old_Units.Foot / ISO_Metric_Units.Second**2;
        -- feet per second per second

      Accel_MPS2 : Magnitude;
      for Accel_MPS2'Unit use
        ISO_Metric_Units.Meter / ISO_Metric_Units.Second**2;
        -- meters per second per second

   begin

       Accel_FPS2 := 32.0  -- "Feet per second squared" implied

        -- now convert units like this:
       Accel_MPS2 := Accel_FPS2 * Accel_MPS2'Unit / Accel_FPS2'Unit;

       -- or this:
       Accel_MPS2 :=
         Accel_FPS2 * ISO_Metric_Units.Meter / Goofy_Old_Units.Foot;


provided that every base unit (distance, mass, time, charge, etc.) attribute
had a corresponding named number whose value was the ratio of the named unit
to the ISO base unit.  For example:

   ISO_Metric_Units.Meter     :=    1.0;     -- value in meters
   ISO_Metric_Units.Kilometer := 1000.0;     -- value in meters
   Goofy_Old_Units.Foot       :=    0.3048;  -- value in meters

This idea is still half-baked but I'll keep thinking about it.  It would be
nice to have some type of dimensional unit support specified in an optional
Annex for Ada 200X.

Britt

   P.S.  The example in my first post should have been a "procedure", not a
"package body"



 





^ permalink raw reply	[flat|nested] 78+ messages in thread
* Re: Dimensionality Checking (Ada 20XX)
@ 2001-12-11 13:11 Mike Brenner
  2001-12-11 17:03 ` Mark Lundquist
  0 siblings, 1 reply; 78+ messages in thread
From: Mike Brenner @ 2001-12-11 13:11 UTC (permalink / raw)
  To: comp.lang.ada

Mark Lundquist said: 
> But the compiler only has to look at the generic *spec* to determine this.
> What you *never* see today, and what we'd really like to avoid in any
> language revision, is this: you make a change to the generic *body*, the
> change is legal (the generic body compiles), but suddenly one or more
> *instantiations* become illegal as a result.  That is the problem I'm
> talking about with units.

Is this the reason why non-generic packages have been forbidden as generic parameters? 

It seems that the benefits of a fully orthogonal implementation of generic (making them second-class objects by permitting passing object to objects) outweigh the benefits of keeping compatibility with all existing bodies. 

In particular, permitting non-generic package parameters would give a way to switch implementations without rewriting the code. In particular, a configuration manager could simply swap the spec and body of the package being used as a non-generic parameter to a generic, and that would change the device driver from being Linux-compatible to being COM-compatible. 

Now, a line of code has to be changed in order to swap devices supported, so it requires a PROGRAMMER rather than a CONFIGURATION MANAGER to make that kind of change to a large Ada system.

The disadvantage would be that certain programs might no longer compile, for example, if they used a feature of Linux that COM-objects did not implement.

It seems to me that this disadvantage, detected at compile time, might make up for the advantage?

Also, of course, making packages second class objects like that would be the penultimate step towards eventually making package first-class objects.




^ permalink raw reply	[flat|nested] 78+ messages in thread
* Another Idea for Ada 20XX
@ 2001-12-02 16:01 James Rogers
  2001-12-03 14:56 ` Mark Lundquist
  0 siblings, 1 reply; 78+ messages in thread
From: James Rogers @ 2001-12-02 16:01 UTC (permalink / raw)


In scientific terms a measurement is done in terms of some unit.
For instance, distance is in meters, microns, feet or furlongs.
Speed is then calculated as a distance per unit time. Acceleration
is the second derivative of speed.

I would like to have this notion of measurement units and their
relationships supported in a language. This would require the language
to perform unit analysis while performing static or run-time 
calculations. Because of the added computational overhead, there must
be a way to choose or reject unit analysis for defined types.

Perhaps a new keyword for unit-analyzed types could be introduced,
along the lines of the keyword "tagged" added to Ada 95. A unit-
analyzed type would carry its own unit description tag to 
facilitate unit analysis. Any numeric type without such a tag
would not be subject to unit analysis.

Possible declarative syntax might be:

type Meters is unit range (0.0..1.0E380);
type Hours is unit range (0.0..9.99E30);
type Speed is unit(Meters / Hours);

The advantage for the software developer is in the usage:

Vehicle_Speed : Speed;
Track_Distance : Meters;
Lap_Time : Hours;

Speed := Track_Distance / Lap_Time;

This approach would allow the appropriate mixing of data types, which
is currently forbidden by Ada, in a meaningful and correct manner.

I know this proposal places a heavy burden upon compiler writers.
I also suspect it would be very useful for ensuring the correctness
of programs, particularly in embedded systems. 

Note that a lot of the unit analysis could be performed statically.
This would allow minimal performance penalty at run time.

Jim Rogers
Colorado Springs, Colorado USA



^ permalink raw reply	[flat|nested] 78+ messages in thread

end of thread, other threads:[~2001-12-27 17:18 UTC | newest]

Thread overview: 78+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
  -- strict thread matches above, loose matches on Subject: below --
2001-12-11 13:11 Mike Brenner
2001-12-11 17:03 ` Mark Lundquist
2001-12-02 16:01 Another Idea for Ada 20XX James Rogers
2001-12-03 14:56 ` Mark Lundquist
2001-12-03 15:12   ` Lutz Donnerhacke
2001-12-03 21:13     ` Dimensionality Checking (Ada 20XX) Nick Roberts
2001-12-04 14:00       ` 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

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