Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Correct Behaviour? Was False = 2 ????

From: joel:neely:fedex at: 2-Jul-2001 16:38

Hello, all, Having already expressed some opinions (perhaps too many ;-) in this area, I felt inclined to listen for a while. I think there are a couple of points that haven't come up that are worth considering. [Robbo1Mark--aol--com] wrote:
> 1. Should Series! Index begin at Zero? >
I'd rephrase as "What are the pro/con tradeoffs for having series indices begin at 0 or 1? If there are advantages to having 0-origin indexing, do those advantages outweigh the effort of conversion of existing code?" Let me pose a practical programming question: given
>> a: [2 3 5 7 11 13 17 19] == [2 3 5 7 11 13 17 19] >> b: at a 5 == [11 13 17 19] >> c: at b 3 == [17 19]
what is the relationship between A and C? I.e., what value of X makes pick a x equivalent to pick c 2 Answering this question (or explaining the answer) in a 1-origin scheme (actually, any non-0-origin scheme) seems to involve the distinction between absolute indices and relative indices, which combine according to the following rules: absolute - absolute is relative absolute + absolute is useless/misleading relative +/- relative is relative absolute +/- relative is absolute The relative index of B in A is (5 - 1). The relative index of C in B is (3 - 1). Therefore, the absolute index of C/2 in A is (5 - 1) + (3 - 1) + (2 - 1) + 1 = 8. If all indexing were 0-origin, the distinction between absolute and relative indexes goes away. The above example would have read ;; a: [2 3 5 7 11 13 17 19] == [2 3 5 7 11 13 17 19] ;; b: at a 4 == [11 13 17 19] ;; c: at b 2 == [17 19] and the position of C/2 relative to A would be 4 + 2 + 2 = 8. Remember that it wasn't until western civilization gave up the 1-origin Roman numerals and began using the 0-origin decimal system that arithmetic really began the uphill climb to becoming Mathematics.
> 2. Should 0, None & False be equivalent > for 'PICKing values from a series! and > return the FIRST or index 0 value whereas > True and 1 would return the SECOND or > Index 1 value? >
There's another lurking inconsistency, which has nothing to do with converting to/from integers. Consider that
>> logblk: reduce [
[ 1 < 2 1 > 2 2 < 1 2 > 1 [ ] == [true false false true]
>> sort logblk == [false false true true]
Doesn't it seem odd that SORT thinks that FALSE precedes TRUE, and yet PICK thinks that FALSE *follows* TRUE? Surely the ordering of values within a type is a meaningful concept, whether or not we try to convert to/from some other type? -- It's turtles all the way down! joel'dot'neely'at'fedex'dot'com