John Cowan wrote:
> All of these sequential representations have advantages for
> some purposes and disadvantages for other purposes.
> Rarely is random access to the components of the string
> particularly useful; what's important is providing fast iteration
> over those components.
I agree 100%. Unfortunately, many languages don't have a way to
iterative except by index. It would be better to have an
abstract position P, plus various X operations to yield the
pair (next X starting at P, position following that X),
perhaps integrated with some kind of parsing / pattern-matching
engine. In lieu of abstract positions, most languages use an
integer index, and specifically (number of characters before P),
where "character" can be "code point" (Java) or "Unicode scalar
value" (Scheme, XQuery/XPath/XSLT), or "byte" (direct UTF-8 or
ASCII or Latin-X access).
Given that programmers will use "character index" as offered
by the language, a language implementor needs to implement that,
preferably with O(1) time, or not be properly compliant.
I don't know how many languages use "string" to mean "sequence
of Unicode scalar value"; if it's just the ones I mentioned,
then perhaps it may be unreasonable to ask for the kind of
support I asked for. It is of course possible to implement
"sequence of Unicode scalar value" on Java as-is; it just
one can't use Java strings directly, which makes interoperability
with Java more difficult.
> I hope that as time goes on, just as languages have accepted
> Unicode as a base representation, they will come to accept
> iterators as a base access method, with strings seen as
> neither atoms nor sequences, but a tertium quid that can
> be iteratively dissected into parts (which are also strings) in
> any of a large variety of ways.
Right, especially since these day a "string" may have further
structure, such as nested "elements". An iterator or "position"
framework also can also handle structured data better.
--
--Per Bothner
[EMAIL PROTECTED] http://per.bothner.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM
Languages" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---