[REBOL] Re: On ordinal and cardinal numbers...
From: jeff:rebol at: 7-Jul-2001 13:14
> > LENGTH?
> >
>
> I wouldn't see a change here. The block below has a length
> of ten elements, regardless of which way the positions are
> labeled IMHO.
>
> 1-org 1 2 3 4 5 6 7 8 9 10
>
> block [ a b c d e f g h i j ]
>
> 0-org 0 1 2 3 4 5 6 7 8 9
>
> just as there are ten numbers in each of the sets {1
> ... 10} and {0 ... 9}
Okay, but the important caveat for everyone to remember is
that with 1-based indexing, LENGTH? blk corresponds to the
range of positions that can be picked from, changed, etc.
However, with zero-based indexing, LENGTH? blk refers to 1+
the range of values pickable, changable.
So, for example, the following code behaves
differently depending on the base:
x: [1 2 3]
change at x length? x 0
1-based == [1 2 0]
0-based == [1 2 3 0]
This leads to a change of REPEAT as part of a very common
REBOL idiom:
repeat i length? block [ print [i pick block i ] ]
Works for 1-based, but without changing both REPEAT and
LENGTH? will break for 0-based (skips the zeroth element and
prints NONE on the final iteration).