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

List.invert only works if the list contains Pairs but the error message isn't very clear about that fact #5540

Closed
p6rt opened this issue Aug 6, 2016 · 6 comments
Labels
at_larry LTA Less Than Awesome; typically an error message that could be better

Comments

@p6rt
Copy link

p6rt commented Aug 6, 2016

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

Searchable as RT128860$

@p6rt
Copy link
Author

p6rt commented Aug 6, 2016

From @dogbert17

dogbert@​dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -v
This is Rakudo version 2016.07.1-128-g715b822 built on MoarVM version 2016.07-16-g85b6537
implementing Perl 6.c.

dogbert@​dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -e 'say (1,2,3).invert'
Method 'value' not found for invocant of class 'Int'
  in block <unit> at -e line 1

http://irclog.perlgeek.de/perl6/2016-08-06

12​:58​:01 dogbert17 | m​: say (1,2,3).invert # ??
12​:58​:01 +camelia | rakudo-moar 589061​: OUTPUT«Method 'value' not found for invocant of class 'Int'␤ in block <unit> at <tmp> line 1␤␤»
12​:59​:18 lizmat | dogbert17​: all I can say is that TimToady added/changed it early 2015

...

13​:16​:34 lizmat | apparently you can only List.invert if the List contains pairs
13​:18​:13 lizmat | dogbert17​: so In guess the right course of action would be to rakudobug it as a @​LARRY bug
13​:20​:02 dogbert17 | lizmat​: so the bug is that it only handles list of pairs?
13​:21​:02 lizmat | well, I guess the bug is that the error is really LTA if the list does not consist of pairs *OR* it should call .pairs on itself first before inverting
13​:21​:13 lizmat | (aka, be the same as .antipairs)

@p6rt
Copy link
Author

p6rt commented Aug 8, 2016

From @zoffixznet

My vote is to not have .invert on listy things at all.

The fact that it can't work in some cases, depending on what things a list contains, is a good indication to me that it's not a list method.

The second option for me would be to improve the error message and make it work only on lists with just Pairs in them, so
that .invert on (1, 2, 3).pairs (which returns a Seq of Pairs) can be used without surprises of .pairs called again under the hood.

@p6rt
Copy link
Author

p6rt commented Aug 8, 2016

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

@p6rt
Copy link
Author

p6rt commented Aug 13, 2016

From @TimToady

Binding of the map routine internally now requires list elements to bind as Pair, which improves the error message.

(The alternate approach of inserting a CATCH into the map closure could in theory produce an even better message, but it appeared to slow things down more than the Pair binding approach.)

Note that we cannot make the degenerate case of .invert the same as .antipairs, because .invert must expand list values into multiple antipairs. In any case, .antipairs is 5-10 times faster since it doesn't have to check for such expansion.

Fix in baeabb4c4e8f5d223da8632130b4dfcd020d40ba

Test in 63c1f009b910a5c87186b2201383682ad7a0f724

1 similar comment
@p6rt
Copy link
Author

p6rt commented Aug 13, 2016

From @TimToady

Binding of the map routine internally now requires list elements to bind as Pair, which improves the error message.

(The alternate approach of inserting a CATCH into the map closure could in theory produce an even better message, but it appeared to slow things down more than the Pair binding approach.)

Note that we cannot make the degenerate case of .invert the same as .antipairs, because .invert must expand list values into multiple antipairs. In any case, .antipairs is 5-10 times faster since it doesn't have to check for such expansion.

Fix in baeabb4c4e8f5d223da8632130b4dfcd020d40ba

Test in 63c1f009b910a5c87186b2201383682ad7a0f724

@p6rt
Copy link
Author

p6rt commented Aug 13, 2016

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

@p6rt p6rt closed this as completed Aug 13, 2016
@p6rt p6rt added at_larry LTA Less Than Awesome; typically an error message that could be better labels Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
at_larry LTA Less Than Awesome; typically an error message that could be better
Projects
None yet
Development

No branches or pull requests

1 participant