• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r4wp

[#Red] Red language group

Andreas
16-Nov-2012
[3723x3]
Path notation is somewhat rarely used with negative indices (and 
probably even rarer with computed components, which I think were 
only added as late as R2.6).
I did some investigation over the rebol.org library and a few other 
available R2 apps a while back, I think it's basically always /-1 
and /-2 for negative path indices.
0th is not that unnatural. I looked into an English dictionary yesterday, 
and actually found it defined as "the item before the first".
DocKimbel
16-Nov-2012
[3726]
I use it often, there are 15 occurences of /-1 in Red codebase.
Andreas
16-Nov-2012
[3727]
Yes, as I said: almost always /-1 and /-2.
DocKimbel
16-Nov-2012
[3728]
I agree.
Andreas
16-Nov-2012
[3729x2]
So even with just two convenience functions for those cases we'd 
probably cover the majority of uses.
(And could keep R3's behaviour for computed indices.)
DocKimbel
16-Nov-2012
[3731]
Maybe, but we still have the 0 index issue, `series/0`giving you 
access to item before current series position is IMO highly confusing.
Andreas
16-Nov-2012
[3732x3]
Not really.
I don't find it particularly confusing that 0 is the integer before 
1.
So quite obviously s/0 should give you the element in s that is before 
s/1.
DocKimbel
16-Nov-2012
[3735]
I bet most readers here and R3 users will find it confusing. See 
my above `pick at values 2 0` example.
Andreas
16-Nov-2012
[3736]
That's just because they are familiar with another equally confusing 
behaviour.
DocKimbel
16-Nov-2012
[3737]
IMO, as long as we are in a 1-based system, s/0 will be confusing 
to most users.
BrianH
16-Nov-2012
[3738]
Pekr, the reason it works for Python is because their series are 
always referenced from the start, so negative indices/offsets would 
otherwise have no meaning. REBOL has offset references to series, 
so negative indices/offsets already have a meaning for us.
DocKimbel
16-Nov-2012
[3739x2]
s[0] is not confusing in C (even if newbies have sometimes issues 
with 0 itself), because C is 0-based.
Brian: except for the "learning new meaning" effort, do you see any 
other cons for having negative indexes work from tail?
Andreas
16-Nov-2012
[3741]
The observation that we are using "a 1-based system" alone doesn't 
help you in any way with that.
BrianH
16-Nov-2012
[3742]
I must have missed the proposal of BASIS?, but the fact that it would 
be a function or variable implies that it would be used to detect 
a global setting, like system/options/binary-base. Global settings 
like that have proven to be a universally bad idea in practice. Local 
settings are better.
Andreas
16-Nov-2012
[3743]
In a pure 1-based system, you have neither 0 nor negative indices.
DocKimbel
16-Nov-2012
[3744]
Agreed.
Andreas
16-Nov-2012
[3745]
BrianH: BASIS? was proposed as the 0-based INDEX? dual.
BrianH
16-Nov-2012
[3746]
Doc, it's not the "learning a new meaning", it's losing the meaning 
they already have. We need the meaning we have, we need to be able 
to reference offsets from before the current position.
DocKimbel
16-Nov-2012
[3747]
Still the fact that `pick series 1` gives you the first item from 
current series position, makes the 0 position awkward.
Andreas
16-Nov-2012
[3748x3]
Why?
0 is before 1, so pick 0 should give you the element before 1.
Actualy, as Ladislav repeatedly explained, having "pick -1" _not_ 
giving you the current element is just as awkward.
BrianH
16-Nov-2012
[3751]
Andreas, oh good, whew. In R3 we're already having to replace all 
system options that affect MOLD with options to the MOLD function 
itself. It would be a shame to have to do the same for all of the 
indexing functions. Nonetheless, that meaning of BASIS? doesn't make 
sense for the name either, so I don't like it.
Andreas
16-Nov-2012
[3752]
You can basically do:
- no 0 or negative indices at all

- disallow 0, have 1 return the next element forward, -1 the next 
element backward (R2)

- disallow 0, have 1 return the current element forward, -1 the current 
element backward

- allow 0, have 1 return the next element forward, 0 return the element 
before that


All have their advantages and disadvantages. All require explaining 
and may not be obvious depending on what you expect.
DocKimbel
16-Nov-2012
[3753]
Yes, but that's not how my brain see it by default, I need to make 
a conscious effort for that. Also, I might be tempted to then use 
0 to access the first item instead of 1...This is a pitfall where 
almost every new (and maybe some older too) will fall in.
Andreas
16-Nov-2012
[3754x2]
Yes, but don't try to generalise from your brain to "most" or "new" 
users.
The only somewhat arguable generalisation is to "those who are well-used 
to R2's behaviour".
DocKimbel
16-Nov-2012
[3756]
I know, but I must try to put myself in future Red users shoes to 
be able to make decisions.
Andreas
16-Nov-2012
[3757]
I think for future Red users, R2's model is actually the worst choice.
BrianH
16-Nov-2012
[3758]
If we do R2's behavior, make sure that PICKZ and POKEZ exist so I 
have something to use. They can call PICK and POKE internally. I 
need something that does computed indexes/offsets, and I can't afford 
to have a hole in the list (0 for R2), and I can't count on the port 
scheme supporting SKIP.
Andreas
16-Nov-2012
[3759]
Just erroring out on index 0 is ann improvement.

Making "pick 1" and "pick -1" return the same element is an improvement.
R3's behaviour is an improvement.

R2's messy behaviour with a clean set of SKIP, PICKZ, POKEZ is an 
improvement.
BrianH
16-Nov-2012
[3760]
If I'm not doing computed indices/offsets, or doing negative/0 offsets, 
or using using port scheme4s where PICK/POKE mean something different, 
then I don't use PICK/POKE at all.
DocKimbel
16-Nov-2012
[3761]
and I can't afford to have a hole in the list

 Brian, could you give us some short code cases where this was a problem 
 for you? This would really help.
BrianH
16-Nov-2012
[3762]
pick ser idx + off
DocKimbel
16-Nov-2012
[3763]
Just erroring out on index 0 is ann improvement.

 That's my intention for Red until we get a consensus on a better 
 overall solution.
Andreas
16-Nov-2012
[3764]
We won't get consensus on this.
DocKimbel
16-Nov-2012
[3765]
We won't if we stick to only R2/R3 options. Fortunately, there are 
other ones, maybe we'll find more.
BrianH
16-Nov-2012
[3766]
Sorry, I didn't mean off in the sense of false, I meant short for 
an offset. Any place where you have computed indexes can have a computation 
that turns out to be less than 1, especially if your base position 
is offset.
Andreas
16-Nov-2012
[3767x2]
Error out and add PICKZ, POKEZ while at it. That would at least give 
us a base to work with.
The problem with keeping most of R2's behaviour much longer is that 
switching to something different will only get harder.
DocKimbel
16-Nov-2012
[3769]
Agreed.
BrianH
16-Nov-2012
[3770]
Remember, R3's behavior isn't done either. There's a standing consistency 
bug, for instance. If we come to a consensus, R3 is likely to adopt 
it too.
Andreas
16-Nov-2012
[3771x2]
So if, for example, we were to switch to 0-based indices-as-offsets 
complemented with an ordinal! type, it's better to do this sooner 
rather than later.
BrianH: CC for this consistency bug?