From: Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov>
Subject: Re: Safe Units Handling in Ada
Date: 21 May 2002 11:58:33 -0400
Date: 2002-05-21T16:05:36+00:00 [thread overview]
Message-ID: <u4rh1lcgm.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: u3cwlbz02.fsf@FWILSON.i-did-not-set--mail-host-address--so-shoot-me
Fraser Wilson <newsfraser@blancolioni.org> writes:
> After a recent discussion, I put together Macks, a small program that
> generates Ada packages for dealing with physical units in a type safe
> way.
I've downloaded it and read the README and example.macks, and compiled
everything; looks good!
One quibble; example.macks says "Energy is Force / Second;". In the
real world, there is no simple relationship among Energy, Force, and
Second. Energy is Joules = kg m^2 / s^2; Force is Newtons = kg m /
s^2.
You can have "Energy is Kilogram * Square_Velocity or Force * Meter;".
(And yes, I did actually get out my physics text to check this :).
Also, is there a description of the grammar allowed in .macks files? I
assume I could work it out by reading the Ada code, but a
user-readable description would be useful. Hmm, looks like the only
thing missing from example.macks is "or", and if you use my definition
of Energy above, you get that (assuming I used "or" correctly). So
maybe that's enough; just add some comments to example.macks.
Looking at the output of "macks example.macks", I'd like a way to put
in a copyright notice; maybe have macks copy the first contiguous
comment in the source file?
Did you try using "pragma Import (Intrinsic, "*")", instead of
providing a body? That sounds like a good idea to me. Looking at the
assembly code generated by
gnatmake -O3 -gnatn example_success -cargs -save-temps
there are no function calls for "*", so pragma Inline is enough. But
'pragma Import (Intrinsic)' seems more elegant, and may save
compilation time, which may or may not be an issue.
In example_fail.adb, the statements
N := Kg * MpS / S;
N := Kg * M / S / S;
can be made to compile by adding parens:
N := Kg * (MpS / S);
N := Kg * ((M / S) / S);
I agree it would be nice if the parens were not necessary, but I don't
mind them.
Finally, what is the derivation of the word "Macks"?
--
-- Stephe
next prev parent reply other threads:[~2002-05-21 15:58 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-05-21 10:01 Safe Units Handling in Ada Fraser Wilson
2002-05-21 14:21 ` Pat Rogers
2002-05-21 15:58 ` Stephen Leake [this message]
2002-05-22 8:32 ` Fraser
2002-05-22 10:21 ` Fraser
2002-05-22 16:37 ` Stephen Leake
2002-05-23 10:16 ` Fraser
2002-05-23 16:03 ` Stephen Leake
2002-05-22 22:44 ` William C. Brennan
2002-05-23 8:55 ` Russ
2002-05-23 9:28 ` Fraser
2002-05-23 10:03 ` martin.m.dowie
2002-05-23 10:24 ` Fraser
2002-05-23 11:03 ` martin.m.dowie
2002-05-23 15:57 ` Dan Andreatta
2002-05-23 16:15 ` Fraser Wilson
2002-05-23 16:48 ` martin.m.dowie
2002-05-23 9:04 ` Russ
2002-05-23 10:01 ` Fraser Wilson
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox