From: Twylite <tw...@cr...> - 2005-07-06 08:10:06
|
'subst' is related to the Tcl interpreter, and can do things one would not expect of a generic string processing function (variable and command substitution). I believe that makes it special enough to remain its own command. 'scan' seems to be appropriate for inclusion in 'string' (it operates on a string, and this structure would be consistent with the 'binary' command). On the other hand, 'format' does not (strictly speaking) take a string as an argument an operate on it. As for 'split' and 'join'; well, Brian's placement of them sees logically correct: 'split' acts on a string and must therefore be part of 'string'; while 'join' acts on a list and should be part of 'list'. But I have to admit that 'string' isn't the most obvious place to look for a 'split' command. In fact all of these commands ('format', 'scan', 'split' and 'join', even 'subst') as well as 'regexp' and 'regsub' are about parsing or combining more than they are about string or list manipulation. It would seem to me that they don't belong in 'string' or 'list', but could belong to some other ensemble if we could find an appropriate name for it. At the same time, it seems like a good plan to get them out of the global namespace (other than 'subst'), even if they have to become part of 'string' and 'list'. While we're talking about 'string' command options, can I propose two new ones: 'string insert string /index/ /string2/' : inserts string2 at position index in string. I believe this is required as 'string replace' must remove at least one character, leading to nasty workarounds to insert without deleting. 'string endswith /string1/ /string2/' : there is no need for a 'startswith' because you can use [string first s1 s2] == 0, but to check if a string ends with a particular substring currently requires the use of [string length] and [string first] (or last), again causing non-obvious code. Returns 1 (true) or 0 (false). Twylite |