On 2/5/07, David Green wrote:
Then we wouldn't need * to count backwards, although it's still useful to allow us to count past the end of an array. There are all sorts of variations on this scheme, such as whether * is the last element or the one after that, etc., or whether 0 should be the first element or the last, and so on.


In some ways, I like not having a [0] index at all: programmers may be used to counting from zero, but normal humans start with first, second, third, ... third last, second last, ["first"] last, so it would make sense to count:
        @[EMAIL PROTECTED], 2, 3, ..., -3, -2, -1]

And then to count past the ends, something like:
        [..., -*-2, -*-1, -*, 1, 2, 3, ..., -3, -2, -1, +*, *+1, *2, ...]

Or since * stands for everything, maybe that should be ..., *-2, *-1, * , *+1, *+2, ...? The thing I like best about this option is that it most clearly preserves the notion of "*" as "everything"; *-1 is the element before everything, and *+1 is the element after everything else.


If there is a way to work "modulated" (cyclic/wrap-around) arrays into this, then we'd want to have a zero in there somewhere, although it still wouldn't have to be first; instead count first, second, third, ..., last but two, last but one, last:
        [1, 2, 3, ..., -2, -1, 0]

(So, for a mod-4 array, @[EMAIL PROTECTED],2,3,[EMAIL PROTECTED],6,7,[EMAIL PROTECTED],-2,-1,0] etc.?)


Yet another way (that avoids distinct +* and -*) is:
        [..., -2,-1] @foo[0, 1, 2, ..., *-2, *-1] [+*, *+1, *+2, ...]
(or     [..., -1, 0] @foo[1, 2, 3, ..., *-1, +*] [*+1, *+2, ...] or something.)

Then *+/-n always refers to the end point, and we can count continuously across the front end of an array or the back.


-David

Reply via email to