Artifact 275eaecf086180650fb4d60414b8e3908dc92b5b1ae94c95d669853033da8f54:
- File doc/dev/strings.md — part of check-in [fbe0d392c7] at 2021-03-12 17:44:49 on branch tcl9-design — WIP (user: dgp, size: 1486) [annotate] [blame] [check-ins using]
Design of Tcl string values for Tcl 9
DRAFT WORK IN PROGRESS. NOT (YET) NORMATIVE
All Tcl values are strings, but what is a string?
The aim of this document is to spell out what the answer to that question has been, what it should be, and how we get from one to the other.
Fundamentals
A string is a sequence of zero or more symbols, each symbol a member of a symbol set known as an alphabet. For example, the Tcl string cat is the sequence of three symbols c, a, t.
Each symbol in the Tcl alphabet is associated with a non-negative integer, known as the code of that symbol. Distinct symbols have distinct codes. Schemes that associate symbols with code values are known as character sets. For example, in Tcl's character set, the symbols c, a, and t are associated with code values 99, 97, and 116 respectively.
There is an ordering imposed on the alphabet by the order of associated code values. This ordering allows symbols to be compared and sorted. The natural extension of that ordering to sequences established one well defined way to compare, order and sort string values.
The number of symbols in a string's symbol sequence is the length of that string.
A symbol within a string can be identified by its place in the sequence, counting with an index that starts at 0. A string of length N has a symbol at each of the index values 0 through N-1.