On Sun, 13 Apr 2008 16:52:00 -0700 (PDT), Eric Hughes wrote:
> Speaking formally, which I was trying to do (but failing in the
> details), almost-a-string is a subset of not-a-string. Axiom
> satisfaction has sharp boundaries that don't usually coincide with
> ordinary conceptual boundaries. Informally, sure, they're both
> strings. But the Ada String type, with its padding, does not satisfy
> the axioms of universal_string. The problem is that it's a fixed
> array, not a fixed array allocation with a variable length like
> Bounded_String. If I assign the value "A", a String of length 1, to a
> String(2), the length of its value as a universal_string changes from
> 1 to 2. So even simple assignment violates the axioms.
If we had universal_string, it would have no assignment anyway, because
all
universal objects are immutable.
There is a difference between types and their constrained subtypes in
terms
of substitutability. That's why the language has Constraint_Error defined.
The contracts extended by Constraint_Error aren't violated and everything
is fine.
> The problem that was the nexus of the original discussion is that
> string literals are of type String and not deemed elements of
> universal_string.
I don't see any harm here. You cannot assign literals.
BTW, there are funny language rules which prevent things like this:
type Integer is range -5..5; -- On some tiny machine
L : constant := ("abcd" & "defg" & "defg")'Length / 3;
-- Illegal anyway
So you cannot exploit the limitation of the string index being Positive in
order to construct strings longer than the index at compile time.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


|