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

What should the behaviour be for .pick / .roll with negative numbers? #5866

Open
p6rt opened this issue Dec 7, 2016 · 4 comments
Open

What should the behaviour be for .pick / .roll with negative numbers? #5866

p6rt opened this issue Dec 7, 2016 · 4 comments
Labels
RFC Request For Comments

Comments

@p6rt
Copy link

p6rt commented Dec 7, 2016

Migrated from rt.perl.org#130284 (status was 'open')

Searchable as RT130284$

@p6rt
Copy link
Author

p6rt commented Dec 6, 2016

From @AlexDaniel

Code​:
say 42.roll(-1)

Result (HEAD)​:
(42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 ...)

Result (2015.10)​:
()

Bisectable points to rakudo/rakudo@f4e9d5e

IRC discussion​: https://irclog.perlgeek.de/perl6/2016-12-06#i_13693983

@p6rt
Copy link
Author

p6rt commented Dec 7, 2016

From @AlexDaniel

Code​:
say 1.pick(-1)

Result​:
MVMArray​: Index out of bounds
  in block <unit> at -e line 1

There's no “index” in my code, that's a number of elements. We probably want an error message that is not so low-level-ish.

@p6rt
Copy link
Author

p6rt commented Dec 7, 2016

From @zoffixznet

On Tue, 06 Dec 2016 16​:16​:28 -0800, alex.jakimenko@​gmail.com wrote​:

Code​:
say 1.pick(-1)

Result​:
MVMArray​: Index out of bounds
in block <unit> at -e line 1

There's no “index” in my code, that's a number of elements. We
probably want an error message that is not so low-level-ish.

I've added an interim-fix[^1] to stop it crashing like that (and instead complain that it goes a non-UInt), but there doesn't yet seem to be a consensus[^2] on whether we should throw on negatives or treat them as zero (same applies to .roll). For example, `match` throws on negative :nth(), and so does `[][-1]`, but `42 xx -1` treats the negative as zero.

So I'd like to examine more of these methods and routines to come up with some sort of consistency on what we do with out-of-bounds args.

[1] rakudo/rakudo@f367e4edc1
[2] https://irclog.perlgeek.de/perl6/2016-12-07#i_13698488

@p6rt
Copy link
Author

p6rt commented Dec 7, 2016

The RT System itself - Status changed from 'new' to 'open'

@p6rt p6rt added the RFC Request For Comments label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request For Comments
Projects
None yet
Development

No branches or pull requests

1 participant