From: Wilhelm Spickermann <wilhelm.spickermann@t-online.de>
To: comp.lang.ada@ada.eu.org
Subject: Unit handling (was: Another Idea for Ada 20XX)
Date: Tue, 04 Dec 2001 20:02:36 +0100
Date: 2001-12-04T20:02:36+01:00 [thread overview]
Message-ID: <mailman.1007492827.22053.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: <3C0B7141.FEB5E5C1@BMW.de>
--On Monday, December 03, 2001 13:34:09 +0100 Dirk Dickmanns
<Dirk.Dickmanns@BMW.de> wrote:
...
> Besides the work of Lutz, I have:
> http://users.erols.com/whitaker/iss_418.htm
> http://www.dmitry-kazakov.de/ada/units.htm
>
May I add some of my ideas here? They could be realized as an
optional ASIS program checker or as a compiler component and
would not have any execution time penalty or require the tools
to be available to do the compilation. As unit consistency is a
program property, it´s not really necessary to have the tool on
every platform and every site.
The idea is to define the basic SI-Units as named numbers with
value 1.0 and using values like "5.7 * meter / second" in the
program. (The compiler can easily optimize such expressions.)
A pragma for use by ASIS (or the compiler) defines which Units
are to be viewed as basic.
Every variable, constant, parameter or named number will be
associated with a derived unit upon the first assignment seen,
by tracking the operations down to the basic units and all
following assignments will be required to lead to the same
result. Additionally all operations will be checked for
consistency. (As others have already pointed out, there are not
too many operations to be considered, as operations like taking
the logarithm of something can never be applied to something
having a unit)
An additional ASIS-pragma can assign a derived unit to a
variable or parameter where the unit is not associated
implicitly by an initial or default value.
A first sketch using SI as an example:
package Units is
-- The 7 SI units:
Meter : constant := 1.0;
...
pragma Define_Unit (Meter, Kilogram, Second, Ampere,
Kelvin, Candela, Mole);
...
-- SI derived units:
Newton : constant := Meter * Kilogram / Second**2;
...
-- SI accepted derived units:
Liter : constant := 1.0e-3 * Meter**3;
...
end Units;
(No special handling for the child units needed, they just
collect some definitions and try to convince programmers, that
that it´s a bad idea to define a factor "Billion" etc.)
package Units.More is
-- Defined (not experimentally determined) units.
Foot : constant := 0.3048 * Meter;
Foot_US_Survey : constant := Foot / 0.999998;
...
-- experimentally determined units / constants
Electron_Volt : constant := 1.602_177_33e-19 * Joule;
...
end Units.More;
package Units.Factors is
...
Kilo : constant := 1.0E3;
...
Billion_US_FR : constant := 1.0E9;
Billion_OTH : constant := 1.0E12;
...
Kilo_Binary : constant := 2.0**10;
...
end Units.Factors;
I think this notation is readable and could be helpful even
without any tool to do the checks. It does not create any
runtime penalties. It should be possible to implement the
checker in ASIS or as an additional compiler component which may
be switched on or off. It´s not meant as a proposal for Ada
20XX, but if someone would like to view it as one: it would
only introduce conflicts in the two new pragma names.
(It will however not be able to handle units like "decibels" or
"degrees celsius". I view these as pseudo units which only make
mathematical reasoning impossible. They should occur only in the
user interface as common expressions, but I´ve written that in
another mail.)
Wilhelm
next prev parent reply other threads:[~2001-12-04 19:02 UTC|newest]
Thread overview: 26+ 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 ` Wilhelm Spickermann [this message]
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
2001-12-03 17:00 ` Another Idea for Ada 20XX chris.danx
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox