I am playing around with GNAT’s dimensionality checking for physical quantities, which are implemented with the aspects Dimension_System and Dimension, see https://blog.adacore.com/uploads/dc.pdf.
I would like a type which models geometric quantities, i.e. angle, length and volume. For that, we need only a length dimension. However, I can’t get the following example to compile:
package Geometry is
type Quantity is new Float with
Dimension_System => (
(Unit_Name => Meter, Unit_Symbol => 'm', Dim_Symbol => 'L')
);
end Geometry;
Isn’t Unit_Name, Unit_Symbol, Dim_Symbol the correct order? That’s how it appears in all the examples I’ve seen.
Interesting paper by the way! It addresses exactly some of my own concerns with the implementation, particularily the units-as-variables issue. I see that the paper is from 2014; has there been any significant progress on the shortcomings you listed in the last eleven years?
The aspect Dimension_System seems to want more than one dimension. If you add a second dimension to the list, it compiles for me. There may be a way to give it only one dimension, but nothing I tried quickly worked.
I’ve never used the GNAT dimension system, so I do not know whether there are any changes.
I also do not see any ambitions to use any such method of unit checking. See the poll:
Not a single answer.
Isn’t Unit_Name, Unit_Symbol, Dim_Symbol the correct order? That’s how it appears in all the examples I’ve seen.
It is, but the attribute Dimension_System seems to want more than one unit in a positional aggregate. This seems to be another deficiency in this method: Is there a syntax defined for the attribute?
The Dimension_System aspect is used to define a system of dimensions that will be used in subsequent subtype declarations with Dimension aspects that reference this system. The syntax is:
The reason I didn’t reply to it is because I haven’t used any of them for anything serious, though I had plans to for a big project in my last place of [degree-relevant] employment, ad was going to use your SI Units, Checked if possible.
Even such a short note is valuable, so please do enter this in the poll.
From The Big Bang To The Universe presents a simple method successfully in use in several helicopter avionics projects under hard real-time conditions, ready to download. This is the only such method I ever have used. Our requirements specification document was pure numeric, no units given, so no chance to verify the equations. When I asked I got the answer “This is no schoolwork…” which left me speechless!
Someone I met on a conference once told me that they used a unit system reduced to only few unit (mechanics perhaps) with a separate type for each unit. They had dozens of overloaded operations, I do not remember the number, but it was tremendous.
So I think many ponder the idea but soon find out the effect is not worth the expenditure. My poll tries to prove or to refute this.