From: Charlie Date: 2006-06-11T22:05:05+09:00 Subject: Re: Substrings by Position. Matthew Smillie wrote: > On Jun 11, 2006, at 13:08, Charlie wrote: > >>>> Shouldn't a negative indexing work as well? (Below are just >>>> examples, >>>> they currently don't work) It will allow strings to be REVERSED >>>> easily, >>>> and thus doing something new. >>> >>> Negative indexes do work already. You probably mean negative >>> lengths. >> >> Yes, you're right. It just mean lengths with direction. > > I don't think that having negative lengths reflect direction is at > all a natural decision; it's describing the bounds of a substring, > not describing and implicit iteration through individual characters. > In other words, if negative lengths worked, I'd fully expect them to > work like this (y is negative): foo[x, y] == foo[(x+y), y.abs] > > e.g. > > foo = "0123456789" > foo[4,-1] # => 3 > foo[3, 1] # => 3 > foo[4,-2] # => 23 > foo[2, 2] # => 23 > > Conflating string reversal into setting the bounds of the substring > is a mistake, I'd say, particularly since there's already a perfectly > reasonable String#reverse. > > matthew smillie. I gather your opinion. And I'm sure that you know, there's always more than one way of achieving the same result. But having said that, it would be better if the program can reflect, and at the sametime when writing it, record accurately how a process actually works, assuming that you're modelling a real life process. In other words, you can actually guess what's acutally going on by just reading your codes. This is esp true and important in modelling business. Again, just for discussion purposes. Charlie -- Posted via http://www.ruby-forum.com/.