Hi --

On Sun, 10 Jul 2005, Devin Mullins wrote:

> Daniel Brockman wrote:
>
>> Whatever String#[] and all the other String methods index, of course.
>> 
> Depending on the parameter you pass, #[] can return a String or an Integer.
>
>>> There is no clear notion of an "Element" in a String.
>>> 
>> If this is true, then we have a serious problem.  Before doing much
>> anything about its API, we need to decide whether String is a byte
>> array or a character array.  (Presumably, matz & co. already have.)

My understanding (sneaking in a reply to Daniel's post in this reply
:-) was that the conceptual and design decision was that Strings are
not arrays, and are therefore not obliged or constrained to have an
Array-like API (any more than arrays are obliged to have a String-like
API).

> There's no such thing as a character in Ruby. (See any discussion on Unicode, 
> etc. in Ruby.) Strings are Objects (stored in C as char*s, I'd guess). Call 
> the right methods on them, and you can get an Integer representing the byte 
> value at a given position ("Hello"[0]), or another String object representing 
> some manipulation of the String ("Hello"[0..0]). Those are your only means of 
> inspection. That was just a long-winded way of saying "this is true."
>
> Anything I didn't reply to, I probably agree with. Since the String methods 
> don't have a consistent notion of an "element," it doesn't seem it would hurt 
> to choose whichever notion we want for a potential #shift method.

That's true only if there's an imperative to have a String instance
method called "shift".  I don't think there is.  Maybe a left
chop/chomp operation would be a good idea, but I think it should be
called lchop, which would be consistent with other string method
naming (rather than with array method naming).


David

-- 
David A. Black
dblack / wobblini.net