Re: A question about certain language features
- Posted by Mike Nelson <MichaelANelson at WORLDNET.ATT.NET> Mar 22, 2002
- 617 views
foo[1..0] is already a legal (null) slice, using it to mean length(foo) will break existing code. Perhaps a better scheme would be using -1 for the end of the sequence. This is also fairly intuitive: foo[1..3] means the first thru third elements conting from the beginning, and foo[-3..-1] would mean the third thru first elements counting from the end. also something like foo[2..-2] would be legal (this would return the sequence minus the first and last element) Internally a negative slice would be converted like this: foo[-3..-1] becomes foo[length(foo)+1-3,length(foo)=1-1] which can be simplifed in this case to foo[length(foo)-2..length(foo)] Of course, the same negative indexing should apply to subscripts, where it is even more intuitive: foo[4] is the fouth element form the beginning, foo[-4] is the fourth element from the end. -- Mike Nelson