Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PICK and POKE of strings have off-by-one error with indexes < 1. #608

Open
rebolbot opened this issue Feb 9, 2009 · 3 comments
Open

PICK and POKE of strings have off-by-one error with indexes < 1. #608

rebolbot opened this issue Feb 9, 2009 · 3 comments

Comments

@rebolbot
Copy link
Collaborator

rebolbot commented Feb 9, 2009

Submitted by: BrianH

PICK and POKE of string types skip the 0 index, and negative indexes are shifted accordingly. PICK and POKE of block types work correctly.


; PICK of blocks

> > b: skip [a b c] 2
> > == [c]
> > pick b 2
> > == none
> > pick b 1
> > == c
> > pick b 0
> > == b
> > pick b -1
> > == a

; PICK of strings

> > b: skip "abc" 2
> > == "c"
> > pick b 2
> > == none
> > pick b 1
> > == #"c"
> > pick b 0
> > == none  ; should be #"b"
> > pick b -1
> > == #"b"  ; should be #"a"

CC – Data [ Version: alpha 33 Type: Bug Platform: All Category: n/a Reproduce: Always Fixed-in:alpha 55 ]

@rebolbot
Copy link
Collaborator Author

rebolbot commented Feb 9, 2009

Submitted by: BrianH

Note that this bug exists in R2, for blocks as well. This needs to be fixed – it’s like picking and poking in Roman numerals.

@rebolbot
Copy link
Collaborator Author

Submitted by: Carl

See also #857

@rebolbot
Copy link
Collaborator Author

Submitted by: BrianH

See also #609 - the same bug for AT.

Oldes added a commit to Oldes/Rebol3 that referenced this issue Jun 13, 2018
In Rebol2, picking value with index 0 was always returning null. In R3-alpha it was changed that zero index was working like index -1... more at this blog http://www.rebol.net/cgi-bin/r3blog.r?view=0173

I decided to revert this change and let it working as before (and so be compatible with Red too)

So now it works for example like:

>> pick tail "123" -1
== #"3"
>> pick tail "123" 0
== none

and it is also consistent with AT positioning:

>> at tail "123" -1
== "3"

Related issues:
metaeducation/rebol-issues#608
metaeducation/rebol-issues#609
metaeducation/rebol-issues#748
metaeducation/rebol-issues#857
metaeducation/rebol-issues#2117

and also:
metaeducation/rebol-issues#613
hostilefork added a commit to metaeducation/ren-c that referenced this issue Jun 14, 2018
Consensus in general was that the negative indexing behavior of
R3-Alpha was not pleasing.  This restores the historical behavior.
Also makes it so that picking with DECIMAL! will round the decimal
down and use the INTEGER! value, vs. SELECT-ing the DECIMAL.

Commit initiated by Oldes in:

Oldes#5

His comments there:

"In Rebol2, picking value with index 0 was always returning null. In
R3-Alpha it was changed that zero index was working like index -1...
more at this blog http://www.rebol.net/cgi-bin/r3blog.r?view=0173"

"I decided to revert this change and let it working as before (and so
be compatible with Red too)"

"So now it works for example like:"

    >> pick tail "123" -1
    == #"3"
    >> pick tail "123" 0
    == none

"and it is also consistent with AT positioning:"

   >> at tail "123" -1
   == "3"

"Related issues:"

metaeducation/rebol-issues#608
metaeducation/rebol-issues#609
metaeducation/rebol-issues#748
metaeducation/rebol-issues#857
metaeducation/rebol-issues#2117

"and also:"

metaeducation/rebol-issues#613
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant