On Apr 13, 2:10 pm, Robert A Duff <bobd...@[EMAIL PROTECTED]
>
wrote:
> There is no such thing as Ada.Strings.String. I thought maybe you meant
> the package Ada.Strings.Fixed, but that package has no type. It uses
> the predefined type String (which is declared in Standard, and
> therefore visible everywhere), and it _does_ have concatenation ops.
> So I don't understand what you mean.
I meant .Fixed and I meant the regular String type. And I forgot that
concatenation isn't declared. Blah. Sorry for generating confusion.
For my own part, I only use String for string literals.
> I agree that blank-padding is a nearly useless thing to do.
> But you can do a lot with fixed-length strings, so long
> as you program them in a mostly-functional style.
I'm not denying any of that. My critique is pretty much solely about
names.
> String and Unbounded_String are both strings of characters,
> so I don't see why it's "plain wrong". [...]
> Adding some (near-useless) operations on String that do blank-padding
> doesn't suddenly make String not a string type.
No, but it does create a violation of axioms that define
universal_string. Such axioms are essentially those of a semigroup
with the trivial inverse operation where only the empty string has an
inverse. (Perhaps we might also say "maximally non-invertible
semigroup". ) You start adding padding manipulations in there and
these axioms are no longer true.
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.
I'm not denying that having an informally-a-string type which is a
fixed-length array is useful and efficient. It's just not a possible
implementation of universal_string. And it's not like you can't
interconvert, but you should probably not do so silently, because
you're not satisfying a set of common axioms.
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.
There's a second problem, one of usability, that the default string
type ought to be Unbounded_String, because it's closest to
universal_string and would create the fewest surprises (manifested in
exceptions raised). That's really another discussion, though.
Eric


|