On 2/23/20 1:49 AM, Christopher Barker wrote:
I think that the "strings are an iterable of strings", i.e. an iterable of iterables onto infinity... is the last remaining common dynamic type issue with Python.
However, I'd like to see the "solution" be a character type, rather than making strings not iterable, so iterating a string would yield chars, and chars would not be strings themselves, and not be iterable (or a sequence at all).
This would be analogous to other iterables -- they can contain iterables, but if you keep iterating (or indexing), eventually you get to a "scalar", non iterable value.
This works well, for, e.g. numpy, where each index or iteration reduces the rank of the array until you get a scalar.
And we don't seem to have constant problems with functions that expect an iterable of, say, numbers getting passed a single number and thinning it's an iterable of numbers.
But, as stated by the OP, it'll be a long path to get there, so I doubt it's worth it.
In any case, there should be some consensus on what the long term goal is before we start proposing ways to get there.
-CHB
I would agree with this. In my mind, fundamentally a 'string' is a sequence of characters, not strings, so as you iterate over a string, you shouldn't get another string, but a single character type (which Python currently doesn't have). It would be totally shocking if someone suggested that iterating a list or a tuple should return lists or tuples of 1 element, so why do strings to this? Why does string act differently? I'm not sure, but I suspect it goes back to some decisions in the beginning of the language. Making strings non-iterable would be a major break in the language. Making the results of iterating over a string not be a string, but a character type that had most of the properties of a string, except it could hold only a single character and wasn't iterable would break a lot less. Probably the only way to see would be try implementing this on a branch of the compiler, and see how many of existing libraries and open source projects break due to this. -- Richard Damon