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

APPEND/PART refinement clips output if shorter than input block #2383

Open
hostilefork opened this issue Jul 23, 2019 · 1 comment
Open

APPEND/PART refinement clips output if shorter than input block #2383

hostilefork opened this issue Jul 23, 2019 · 1 comment

Comments

@hostilefork
Copy link
Member

hostilefork commented Jul 23, 2019

There is a controversial interpretation of the /PART refinement on APPEND and INSERT which says that it refers to an integer length of how many units of the result series type should be used.

#2096

However, R3-Alpha doesn't quite heed this rule. It uses the length of the source series to clip that limit:

r3-alpha>> append/part "abc" ["defg"] 2     
== "abcd"  ; because the overall block is only length 1, it is clipped

r3-alpha>> append/part "abc" ["defg" "hijk"] 2
== "abcde"  ; increasing the block size changes this around

This comes from a call to Partial1() which takes the source argument in the A_APPEND and A_INSERT case, which it then uses to make the clipping decision. Under the current stated rules of the game, it doesn't know where to clip, so it needs to leave that decision up to Modify_String().

Moreover, it probably should only accept an INTEGER!...as taking series positions for a /PART under this rule do not make sense! Red has that problem as well:

red>> append/part "abc" x: [100 "de" "fg"] next next x
== "abc10"

But it doesn't have the problem with the length clipping:

red>> append/part "abc" ["defg"] 2
== "abcde"

red>> append/part "abc" ["defg" "hijk"] 2
== "abcde"

Though it does seem to interpret negative numbers in a nonsensical-seeming way:

red>> append/part "a" ["bc" "de"] -1 
== "abcde"

red>> append/part "a" next ["bc" "de"] -1 
== "ade"

red>> append/part "a" next ["bc" "de"] -2
== "ade" 
hostilefork added a commit to metaeducation/ren-c that referenced this issue Jul 23, 2019
Resolves issue described here:

metaeducation/rebol-issues#2383

Uses unsigned integers to reduce need for casting in compiler warnings.
hostilefork added a commit to metaeducation/ren-c that referenced this issue Jul 23, 2019
Resolves issue described here, by restricting the /PART refinement to
only take INTEGER!:

metaeducation/rebol-issues#2383

Required a change to REWORD as it was trying to pass in a series
position; this changes it to pass in an offset.

Uses unsigned integers in the implementation to reduce need for casting
in compiler warnings.
@Oldes
Copy link

Oldes commented Sep 19, 2019

Is there any proposition what should be results for above cases?

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

2 participants