[REBOL] Re: Correct Behaviour? Was False = 2 ????
From: agem:crosswinds at: 3-Jul-2001 3:35
RE: [REBOL] Re: Correct Behaviour? Was False = 2 ????
Hello Joel,
[joel--neely--fedex--com] wrote:
> 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.
>
which is (5 - 1) + (3 - 1) + 2 = 8
or [(offset? a b) + (offset? b c) + 2]
and in a simulated 2d-array
y - 1 * width + x ; rebol-order ;-)
instead of
y * width + x
both not to much more complicated.
(aerm, +/- 1 . my preferred error..
usually i get confused with this stuff,
please check.. :)
> 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.
>
Well, we have 0 too :)
for me 1 is more pleasant because i count and i index.
and counting says
i have one, i have two, .., i have length? all-that-here
and i ask others to give me the red easter-egg,
yes, that, the third.
in c i have to code
while[index < length? something]; hu? stopping before the last?!
in rebol
while[index <= length? something]
which makes more sense to me.
and top? stack <> length? stack ?
its goes very common after a while, but
- try then to talk to normal people.. :)
drawback is the slightly less performant index-calculation.
of course a good reason in c.
in rebol i rarely use clever index-tricks
(and have to think then in both worlds).
but 0 needs a mental translation allways without (very big) benefit.
rebol wants to be "plain english for computers" ;-)
> >
> > 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?
>
oops, well, hm, yes, it should be, aerhm, .. ;-)
i think sort hits exactly the middle between both interpretations?
Ah! the heavier values are right? hm?!
fortunally i seldom sort logicals, so i can defer the answer :)
> --
> It's turtles all the way down!
BTW i like the joke.but the first steps were elephants? Terry?! :)
> joel'dot'neely'at'fedex'dot'com
;-) Volker