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

Indexing on a Str throws generic “out of range” message which is less than awesome (“hello”[2]) #5740

Open
p6rt opened this issue Oct 10, 2016 · 4 comments
Labels
LTA

Comments

@p6rt
Copy link

@p6rt p6rt commented Oct 10, 2016

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

Searchable as RT129843$

@p6rt
Copy link
Author

@p6rt p6rt commented Oct 10, 2016

From @AlexDaniel

Code​:
say �hello�[2]

Result​:
Index out of range. Is​: 2, should be in 0..0
  in block <unit> at -e line 1

Actually thrown at​:
  in block <unit> at -e line 1

IRC discussion starting here​:
https://irclog.perlgeek.de/perl6/2016-10-10#i_13370830

@p6rt
Copy link
Author

@p6rt p6rt commented May 8, 2017

From @zoffixznet

On Mon, 10 Oct 2016 06​:05​:10 -0700, alex.jakimenko@​gmail.com wrote​:

Code​:
say �hello�[2]

Result​:
Index out of range. Is​: 2, should be in 0..0
in block <unit> at -e line 1

Actually thrown at​:
in block <unit> at -e line 1

IRC discussion starting here​:
https://irclog.perlgeek.de/perl6/2016-10-10#i_13370830

I don't get why we throw in this case at all. We don't do it with any of the Positionals​:

  <Zoffix_> m​: say $_[42] for 1..1, (1,), [1,], (1,).Seq
  <camelia> rakudo-moar 60f898​: OUTPUT​: «Nilâ�¤Nilâ�¤(Any)â�¤Nilâ�¤Â»

Other than Blob and Uni, which I'd say also break the consistency​:

  <Zoffix_> m​: say "".NFD[1]
  <camelia> rakudo-moar 60f898​: OUTPUT​: «Index out of range. Is​: 1, should be in 0..-1â�¤ in block <unit> at <tmp> line 1â�¤â�¤Actually thrown at​:â�¤ in block <unit> at <tmp> line 1â�¤â�¤Â»
  <Zoffix_> m​: say Blob.new[1]
  <camelia> rakudo-moar 60f898​: OUTPUT​: «Index out of range. Is​: 1, should be in 0..-1â�¤ in block <unit> at <tmp> line 1â�¤â�¤Actually thrown at​:â�¤ in block <unit> at <tmp> line 1â�¤â�¤Â»

The throwage breaks the "everything is a 1-item list" idiom, as I can't safely do $x[1], because
it'll explode any time $x is not a non-Stringy Positional. I tried to remove the throwage, but it's blocked by several 6.c tests.

And regardless of that, I'm -1 on this ticket. Right now $x[1] throws X​::OutOfRange on non-Positionals (even though it shouldn't), but the proposed fix for this ticket would see the possibility of yet another exception in another special case being thrown, all for the sake that *someone new to the language* *assumes* Perl 6 can index strings. IMO such special casing will be a hassle to more normal Perl 6 users than a helpful tip to new Perl 6 users. Just recall how often the Perl-5-ism exceptions get thrown when writing normal Perl 6 code.

@p6rt
Copy link
Author

@p6rt p6rt commented May 8, 2017

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

@p6rt
Copy link
Author

@p6rt p6rt commented May 8, 2017

From @AlexDaniel

I agree with you, but we can do better.

Usually I'm against all perl5 error messages, but I believe that this case is different. I am sure that this is what most people attempt to do at some point. I also know for sure that this is what I did a couple of times when I was starting with Perl 6. I also remember many times people were asking this on the channel.

So here's what I think​:
* A FAQ entry can be added. I created a doc issue for this​: Raku/doc#1300
* I think that it will be possible to add a compile-time error if you do something like ï½¢‘foo’[2]ï½£. That is, if somebody attempts to index a string literal, then we know for sure that it is wrong (… or at least, the error message will do more good than harm).

On 2017-05-08 09​:26​:53, cpan@​zoffix.com wrote​:

On Mon, 10 Oct 2016 06​:05​:10 -0700, alex.jakimenko@​gmail.com wrote​:

Code​:
say “hello”[2]

Result​:
Index out of range. Is​: 2, should be in 0..0
in block <unit> at -e line 1

Actually thrown at​:
in block <unit> at -e line 1

IRC discussion starting here​:
https://irclog.perlgeek.de/perl6/2016-10-10#i_13370830

I don't get why we throw in this case at all. We don't do it with any
of the Positionals​:

<Zoffix_> m​: say $_[42] for 1..1, (1,), [1,], (1,).Seq
<camelia> rakudo-moar 60f898​: OUTPUT​: «Nilâ�¤Nilâ�¤(Any)â�¤Nilâ�¤»

Other than Blob and Uni, which I'd say also break the consistency​:

<Zoffix_> m​: say "".NFD[1]
<camelia> rakudo-moar 60f898​: OUTPUT​: «Index out of range. Is​: 1,
should be in 0..-1� in block <unit> at <tmp> line 1��Actually thrown
at​:â�¤ in block <unit> at <tmp> line 1â�¤â�¤»
<Zoffix_> m​: say Blob.new[1]
<camelia> rakudo-moar 60f898​: OUTPUT​: «Index out of range. Is​: 1,
should be in 0..-1� in block <unit> at <tmp> line 1��Actually thrown
at​:â�¤ in block <unit> at <tmp> line 1â�¤â�¤»

The throwage breaks the "everything is a 1-item list" idiom, as I
can't safely do $x[1], because
it'll explode any time $x is not a non-Stringy Positional. I tried to
remove the throwage, but it's blocked by several 6.c tests.

And regardless of that, I'm -1 on this ticket. Right now $x[1] throws
X​::OutOfRange on non-Positionals (even though it shouldn't), but the
proposed fix for this ticket would see the possibility of yet another
exception in another special case being thrown, all for the sake that
*someone new to the language* *assumes* Perl 6 can index strings. IMO
such special casing will be a hassle to more normal Perl 6 users than
a helpful tip to new Perl 6 users. Just recall how often the Perl-5-
ism exceptions get thrown when writing normal Perl 6 code.

@p6rt p6rt added the LTA label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.