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

Different implementation of nqp::index for Moar and [JVM] (negative startposition) #301

Open
coke opened this issue Jul 27, 2016 · 0 comments

Comments

@coke
Copy link
Contributor

coke commented Jul 27, 2016

Originally opened as https://rt.perl.org/Ticket/Display.html?id=127913 by Christian Bartolomaeus

> The following discussion from november 2015 was linked in ticket
> https://rt.perl.org/Ticket/Display.html?id=125784 which I'm going
> to close.
> 
> I'm opening this separate ticket for the differing behaviour 
> of rakudo-moar and rakudo-jvm with regard to using a negative
> startposition for index (and rindex).
> 
> <bartolin> lizmat: earlier today I found this differing behaviour 
> for moar and jvm:
> <bartolin> r: say index("xxy", "y", -1)
> <camelia> rakudo-moar: OUTPUT«Nil␤»
> <camelia> ..rakudo-jvm 0b6328: OUTPUT«2␤»
> <bartolin> do you think moar is right here?
> * lizmat looks into it
> <bartolin> lizmat++
> <lizmat> r: use nqp; say nqp::index("xxy","y",-1)
> <camelia> rakudo-jvm 0b6328: OUTPUT«2␤»
> <camelia> ..rakudo-moar: OUTPUT«-1␤»
> <lizmat> looks like a difference in implementation of nqp::index
> <lizmat> r: use nqp; say nqp::index("xxy","y",0)
> <camelia> rakudo-moar, rakudo-jvm 0b6328: OUTPUT«2␤»
> <lizmat> bartolin: seems worthy of an NQP ticket
> <lizmat> or perhaps just a rakudobug  :-)
> <bartolin> lizmat: and what do you think is the "better" answer? 
> Perl 5 allows negative start positions, if I'm not mistaken.
> <lizmat> yes, but P5 also allows to use -1 to indicate from end
> <lizmat> so perhaps it should just fail on a negative position
> <bartolin> I see. I'll open a RT for this (probably a bit later).
> <bartolin> thanks for looking!

With a followup narrowing this down to pure nqp behavior:

> Sorry, I got a bit confused:
> 
> The different behavior for routines index and rindex with negative startposition between rakudo-moar and rakudo-jvm was fixed (see https://rt.perl.org/Ticket/Display.html?id=126700).
> 
> What's still relevant is the different implementation of nqp::index:
> 
> $ perl6-m -e 'use nqp; say nqp::index("xxy","y",-1)'
> -1
> 
> $ perl6-j -e 'use nqp; say nqp::index("xxy","y",-1)'
> 2
> 
> Output generated with Rakudo version 2016.03-110-g5bfc8fb.

Which is still happening today:

15:46 < unmatched}> r: use nqp; say nqp::index("xxy","y",-1)
15:46 < camelia> rakudo-moar 3bea9d: OUTPUT«-1␤»
15:46 < camelia> ..rakudo-jvm cd19db: OUTPUT«2␤»

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant