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

Re: using '-1' in array range fails #83

Closed
p5pRT opened this issue Jun 19, 1999 · 2 comments
Closed

Re: using '-1' in array range fails #83

p5pRT opened this issue Jun 19, 1999 · 2 comments

Comments

@p5pRT
Copy link

@p5pRT p5pRT commented Jun 19, 1999

Migrated from rt.perl.org#886 (status was 'resolved')

Searchable as RT886$

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jun 19, 1999

From @Abigail

No.

The reason it isn't in Perl is that the list 3 .. -1 is empty.

Now, theoretically, one could modify perl such that it recognizes 3 .. -1
and does what you do. But that would be a bad idea.

I once argued with a language developer about this; he wanted to be able
to index arrays with negative numbers (in the same way as Perl does), but
I strongly disagreed. Because in that case, the slice

  array [x .. x - 1]

would be empty for all x, except x == 0, where the slice suddenly is the
entire array. (In this language .. only has meaning in array slices).

Negative indices were eventually dropped; just because of this oddity.

Perl doesn't suffer from this oddity, because .. is a list constructer,
however, with your proposal, it would.

Abigail

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jun 19, 1999

From @Abigail

On Mon, May 03, 1999 at 07​:10​:54PM +0200, Rob Urban wrote​:

supposing​:

@​foo = \(1\,2\,3\,4\,5\,6\,7\,8\,9\);

then

print $foo\[\-1\];

yields "9";

Shouldn't

@​bar = @​foo\[3\.\.\-1\];

cause @​bar to be (4,5,6,7,8,9) ?

instead, @​bar is empty.

No.

The reason it isn't in Perl is that the list 3 .. -1 is empty.

Now, theoretically, one could modify perl such that it recognizes 3 .. -1
and does what you do. But that would be a bad idea.

I once argued with a language developer about this; he wanted to be able
to index arrays with negative numbers (in the same way as Perl does), but
I strongly disagreed. Because in that case, the slice

  array [x .. x - 1]

would be empty for all x, except x == 0, where the slice suddenly is the
entire array. (In this language .. only has meaning in array slices).

Negative indices were eventually dropped; just because of this oddity.

Perl doesn't suffer from this oddity, because .. is a list constructer,
however, with your proposal, it would.

Abigail

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