From: Tom Sawyer Date: 2002-07-07T07:54:50+09:00 Subject: Re: is there a better string.each? On Sat, 2002-07-06 at 16:23, Jim Weirich wrote: > I think that's part of the problem. Everyone is coming into this with > their own preconceptions of strings and arrays, and they aren't > matching. indeed, they arn't matching. and it would be nice if we could come to a general agreement about it. this all started with the notion that the String#each method (and related methods) did not keep with POLS, unlike the Array. so the comparison was drawn. > Really? I tend to deal with arrays element by element. With strings, > I usually deal with chunks (i.e. slices) or the entire thing at once. > I usually don't equate a string with an array of characters. They are > different animals in my mind. while i agree with you that typically array's are delt with element by element and string are often delt with "chunks" at a time. both can be, and are, accessed both ways. somtimes you might want a slice of elements from an array. and sometimes you want each character of a string, which goes back to the original premise of this thread. it's silly not to see strings for what they are: an ordered list of characters. granted, one often deals with them on a higher level, but nonetheless that is what they are at root. in contrast, an array is an ordered list of objects. thus, in so far as they are both ordered lists, they should share the same methods. that's basic POLS, and would mean String#each should return the character, not the bytecode. ~transami > >>>>> "Sean" == Sean Russell writes: > > Sean> Michael Campbell wrote: > >> I don't think that "ordered set of characters" implies "Array". > > Sean> I don't know of a better definition of "Array" than "an > Sean> ordered set of somethings". > > Technically, arrays aren't sets. An element may appear in an array > more than once. > > Sean> Linked lists are also ordered sets of somethings; arrays > Sean> just have a particular customary implementation in > Sean> computers. Still, people tend to deal with strings the same > Sean> way they deal with arrays, as opposed to linked lists. > > Really? I tend to deal with arrays element by element. With strings, > I usually deal with chunks (i.e. slices) or the entire thing at once. > I usually don't equate a string with an array of characters. They are > different animals in my mind. > > I think that's part of the problem. Everyone is coming into this with > their own preconceptions of strings and arrays, and they aren't > matching. > > -- > -- Jim Weirich jweirich@one.net http://w3.one.net/~jweirich > --------------------------------------------------------------------- > "Beware of bugs in the above code; I have only proved it correct, > not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas) > -- ~transami "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -- Benjamin Franklin