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

Nested indexing semantics changed from Beijing to nom in Rakudo #2471

Closed
p6rt opened this issue Sep 12, 2011 · 7 comments
Closed

Nested indexing semantics changed from Beijing to nom in Rakudo #2471

p6rt opened this issue Sep 12, 2011 · 7 comments

Comments

@p6rt
Copy link

p6rt commented Sep 12, 2011

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

Searchable as RT98954$

@p6rt
Copy link
Author

p6rt commented Sep 12, 2011

From @masak

<masak> b​: my @​a = [1], [2], [3]; say (map { @​a[1 - $_][0] }, 0 .. 3).perl
<p6eval> b 1b7dd1​: OUTPUT«(2, 1, Any, Any)␤»
<masak> nom​: my @​a = [1], [2], [3]; say (map { @​a[1 - $_][0] }, 0 .. 3).perl
<p6eval> nom 08ef94​: OUTPUT«(2, 1).list␤»
* masak submits rakudobug
<tadzik> here we go again
<masak> tadzik​: this change in semantics causes connect-4 to give the
first player the win on the first move.
<tadzik> masak​: serious business
<masak> tadzik​: seems connect-4's winning condition relied on being
able to do negative indexing.
<masak> tadzik​: I have no trouble believing that this isn't spectested.
<masak> and I have no horse in this race. I'll gladly rewrite that
part of connect-4 if need be.
<masak> but until there's a verdict, it goes into RT.
<masak> niecza​: my @​a = [1], [2], [3]; say (map { @​a[1 - $_][0] }, 0 .. 3).perl
<p6eval> niecza v9-23-g1a8efca​: OUTPUT«(2, 1, Any, Any).list␤» [23​:52]
<masak> there'a another data point, I guess.
<jnthn> nom​: my @​a = [1], [2], [3]; say (map { say @​a[1 - $_][0].WHAT;
@​a[1 - $_][0] }, 0 .. 3).perl
<p6eval> nom 08ef94​: OUTPUT«Int()␤Int()␤Nil␤Nil␤(2, 1).list␤»
<jnthn> nom​: say (map { Nil }, 0 .. 3).perl
<p6eval> nom 08ef94​: OUTPUT«().list␤»
<jnthn> masak​: There's the underlying thing.
<masak> jnthn​: I suspected that.
<masak> jnthn​: why Nil and not Any?
<jnthn> masak​: I can believe that's actually correct. But I'm not
quite sure if the Nil you got before is wrong.
<jnthn> masak​: That is, it's not map's fault..but @​a[1 - $_][0]
returning Nil may be wrong.
<masak> aye.
<masak> I know.
<jnthn> Well, so that golfs if. :)

Does the spec say that one should get Nil in this case? I was fine
with getting Any. Note also that Niecza agrees.

@p6rt
Copy link
Author

p6rt commented Sep 12, 2013

From @masak

On Mon Sep 12 15​:04​:09 2011, masak wrote​:

<masak> b​: my @​a = [1], [2], [3]; say (map { @​a[1 - $_][0] }, 0 ..
3).perl
<p6eval> b 1b7dd1​: OUTPUT«(2, 1, Any, Any)␤»
<masak> nom​: my @​a = [1], [2], [3]; say (map { @​a[1 - $_][0] }, 0 ..
3).perl
<p6eval> nom 08ef94​: OUTPUT«(2, 1).list␤»
* masak submits rakudobug
<tadzik> here we go again
<masak> tadzik​: this change in semantics causes connect-4 to give the
first player the win on the first move.
<tadzik> masak​: serious business
<masak> tadzik​: seems connect-4's winning condition relied on being
able to do negative indexing.
<masak> tadzik​: I have no trouble believing that this isn't
spectested.
<masak> and I have no horse in this race. I'll gladly rewrite that
part of connect-4 if need be.
<masak> but until there's a verdict, it goes into RT.
<masak> niecza​: my @​a = [1], [2], [3]; say (map { @​a[1 - $_][0] }, 0
.. 3).perl
<p6eval> niecza v9-23-g1a8efca​: OUTPUT«(2, 1, Any, Any).list␤»
[23​:52]
<masak> there'a another data point, I guess.
<jnthn> nom​: my @​a = [1], [2], [3]; say (map { say @​a[1 - $_][0].WHAT;
@​a[1 - $_][0] }, 0 .. 3).perl
<p6eval> nom 08ef94​: OUTPUT«Int()␤Int()␤Nil␤Nil␤(2, 1).list␤»
<jnthn> nom​: say (map { Nil }, 0 .. 3).perl
<p6eval> nom 08ef94​: OUTPUT«().list␤»
<jnthn> masak​: There's the underlying thing.
<masak> jnthn​: I suspected that.
<masak> jnthn​: why Nil and not Any?
<jnthn> masak​: I can believe that's actually correct. But I'm not
quite sure if the Nil you got before is wrong.
<jnthn> masak​: That is, it's not map's fault..but @​a[1 - $_][0]
returning Nil may be wrong.
<masak> aye.
<masak> I know.
<jnthn> Well, so that golfs if. :)

Does the spec say that one should get Nil in this case? I was fine
with getting Any. Note also that Niecza agrees.

These days, it fails.

<masak> rn​: my @​a = [1], [2], [3]; say (map { @​a[1 - $_][0] }, 0 ..
3).perl
<camelia> niecza v24-95-ga6d4c5f​: OUTPUT«(2, 1, Any, Any).list␤»
<camelia> ..rakudo 69c3cc​: OUTPUT«(2, 1, Failure.new(exception =>
X​::AdHoc.new(payload => "Cannot use negative index -1 on Array")),
Failure.new(exception => X​::AdHoc.new(payload => "Cannot use negative
index -2 on Array"))).list␤»
* masak amends RT #​98954

Which is arguably more correct than silently truncating the result list.
(But still different from both Beijing and Niecza.)

@p6rt
Copy link
Author

p6rt commented Sep 12, 2013

@masak - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Sep 12, 2013

From @pmichaud

On Thu, Sep 12, 2013 at 11​:48​:02AM -0700, Carl Mäsak via RT wrote​:

These days, it fails.

<masak> rn​: my @​a = [1], [2], [3]; say (map { @​a[1 - $_][0] }, 0 ..
3).perl
<camelia> niecza v24-95-ga6d4c5f​: OUTPUT«(2, 1, Any, Any).list␤»
<camelia> ..rakudo 69c3cc​: OUTPUT«(2, 1, Failure.new(exception =>
X​::AdHoc.new(payload => "Cannot use negative index -1 on Array")),
Failure.new(exception => X​::AdHoc.new(payload => "Cannot use negative
index -2 on Array"))).list␤»
* masak amends RT #​98954

Which is arguably more correct than silently truncating the result list.
(But still different from both Beijing and Niecza.)

S09​:683 says that "Negative subscripts are never allowed for standard
subscripts unless the subscript is declared modular."

I know S09 is slushy, but afair once the whatever star notation was
introduced it's always been the intent that negative indices would
fail unless explicitly declared to be valid somehow.

Pm

@p6rt
Copy link
Author

p6rt commented Dec 13, 2014

From @usev6

The typed exception has changed and AFAIU the current behaviour is correct (cmp. also ticket 111924) :

$ perl6 -e 'my @​a = [1], [2], [3]; say (map { @​a[1 - $_][0] }, 0 .. 3).perl'
(2, 1, Failure.new(exception => X​::Subscript​::Negative.new(index => -1, type => Array)), Failure.new(exception => X​::Subscript​::Negative.new(index => -2, type => Array))).list

I added a test to S02-types/nested_arrays.t with commit Raku/roast@1ecd460c8e. I'm closing this ticket now.

1 similar comment
@p6rt
Copy link
Author

p6rt commented Dec 13, 2014

From @usev6

The typed exception has changed and AFAIU the current behaviour is correct (cmp. also ticket 111924) :

$ perl6 -e 'my @​a = [1], [2], [3]; say (map { @​a[1 - $_][0] }, 0 .. 3).perl'
(2, 1, Failure.new(exception => X​::Subscript​::Negative.new(index => -1, type => Array)), Failure.new(exception => X​::Subscript​::Negative.new(index => -2, type => Array))).list

I added a test to S02-types/nested_arrays.t with commit Raku/roast@1ecd460c8e. I'm closing this ticket now.

@p6rt p6rt closed this as completed Dec 13, 2014
@p6rt
Copy link
Author

p6rt commented Dec 13, 2014

@usev6 - Status changed from 'open' to 'resolved'

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

1 participant