Overview
| Artifact ID: | 28a43fb9ccb5846b81905846b5f3b57ff3c91a4ed0d377f001dbcffc902691c1 |
|---|---|
| Ticket: | 5dabd088eecefd81cf86cf213a2e3e7f25b1329b
TIP 573 discussion |
| User & Date: | dgp on 2020-04-30 15:27:56 |
Changes
- icomment:
The trickiest issue here is that Tcl strings have two uses. First, they are a way to store and process text, and for that purpose increased Unicode conformance is the good way to move the capabilities of Tcl programming into agreement with the expectations of text programming in other languages. However, Tcl strings are also the common foundation of all values in the language. "Everything is a string". If we remove some of the alphabet we can use to make up those strings, we are removing some of the expressible values in that representation set, which can lead to trouble. The same issue came up in the 8.0 -> 8.1 transition. In 8.0 "Everything is a string" meant "Everything is representable as a sequence of bytes", and in order to support all values, Tcl 8.0 was written to support strings covering that entire set of sequences of any byte value. When 8.1 came out, the new support for international character sets brought with it a new rule that the "string" values were conceptually "Any sequence of UCS-2 characters", and when looking at (char *) arguments something similar to UTF-8 would be used to encode that concept. This change meant that at least for some commands, script writers had to become aware of the distinction between "bytes" and "chars". Using the C routines properly demanded even more awareness. If some user of Tcl 8.0 was accustomed to passing the bytes "\xC2\x80" to Tcl and have them reliably treated and preserved as a sequence of two things, Tcl 8.1 broke that contract, because large parts of Tcl now saw and treated that as U+0080. To make up for it, Tcl 8.1 provided bytearrays, so that anyone needing to send arbitrary byte sequences into Tcl free from corruption had a way to do it. In parallel with that, I think if we revise our string definition to exclude the UCS-2 characters that are surrogates in UTF-16, we likewise need some new facility so that any Tcl users that have need to work with UCS-2 arrays can continue to do so. I think there's at least some reason to believe UCS-2 arrays are a concept Tcl programmers need. If I imagine reading from a channel encoded in utf-16, there can be a point where I've read the high surrogate but not yet the low surrogate that follows it. In that moment, I need to store in the variable holding "what I've read so far from the channel" a value that includes an unpaired surrogate. Just like I can currently use a bytearray to hold an incomplete UTF-8 sequence partially read from a binary channel. This probably means expanding the set of concepts for Tcl programming to include bytes, code units, and characters. I think the historical example of 8.0 -> 8.1 establishes that such a change is not absolutely forbidden for 8.7, but it is a change of remarkable scale and potential for disruption. If we contemplate it, I think we are obligated to supply clear migration supports and high quality advice how to navigate it. Does that make sense?
- login: "dgp"
- mimetype: "text/plain"