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

antipairs sub is not implemented #3782

Open
AlexDaniel opened this issue Jul 6, 2020 · 10 comments
Open

antipairs sub is not implemented #3782

AlexDaniel opened this issue Jul 6, 2020 · 10 comments
Assignees

Comments

@AlexDaniel
Copy link
Contributor

AlexDaniel commented Jul 6, 2020

23:34 | AlexDaniel | m: my $s = <a b c>.words; say $s.pairs
23:34 | camelia    | rakudo-moar a74550507: OUTPUT: «(0 => a 1 => b 2 => c)␤»
23:34 | AlexDaniel | m: my $s = <a b c>.words; say pairs $s
23:34 | camelia    | rakudo-moar a74550507: OUTPUT: «(0 => a 1 => b 2 => c)␤»
23:34 | AlexDaniel | m: my $s = <a b c>.words; say $s.antipairs
23:34 | camelia    | rakudo-moar a74550507: OUTPUT: «(a => 0 b => 1 c => 2)␤»
23:35 | AlexDaniel | m: my $s = <a b c>.words; say antipairs $s
23:35 | camelia    | rakudo-moar a74550507: OUTPUT: «=== SORRY!===  Error while compiling <tmp>␤Undeclared routine:␤ antipairs used at line 1␤␤»
23:35 | AlexDaniel | :|
23:35 | AlexDaniel | srsly?
@lizmat
Copy link
Contributor

lizmat commented Jul 7, 2020

Having implemented .antipairs at the time, I remember asking that question, and I seem to remember that it was not deemed necessary.

BTW, this also goes for other string methods, like starts-with, ends-with, substr-eq and possibly more.

@lizmat
Copy link
Contributor

lizmat commented Aug 15, 2020

@AlexDaniel this would be easy to implement. Why don't you give it a try?

@AlexDaniel
Copy link
Contributor Author

@lizmat OK, I didn't know about starts-with and friends. Should I add them too?

@lizmat
Copy link
Contributor

lizmat commented Aug 15, 2020

If you think antipairs should be added, why should starts-with and friends not be?

@AlexDaniel AlexDaniel self-assigned this Aug 15, 2020
@AlexDaniel
Copy link
Contributor Author

Okay. I'm too tired physically today but I'll get back to it later.

@lizmat
Copy link
Contributor

lizmat commented Oct 6, 2020

Can this issue be closed? Or should someone else add these subs?

@AlexDaniel
Copy link
Contributor Author

I don't see why it would be closed. Anyone else is free to do it, yes. Or you can just wait, I don't have that many tickets assigned to me but I do have a backlog of things to do.

@AlexDaniel
Copy link
Contributor Author

By the way, @lizmat, have you thought about some kind of automated way of creating subs for existing methods? As I see it, currently both should be created manually, but maybe there's a way to, let's say, just mark a method that a sub should exist too? Maybe even user libs should be able to use the same mechanism so that they can provide APIs that feel like rakudo std lib does.

@AlexDaniel
Copy link
Contributor Author

To illustrate:

class Foo {
    has $.x;
    submethod bar { $.x × 2 }
}
Foo.new(:42x).bar.say; # 84
say bar Foo.new(:42x); # 84

(Yes, it doesn't work because submethod does something completely different, but what if?)

@lizmat
Copy link
Contributor

lizmat commented Oct 6, 2020

class Foo {
    has $.x;
    method bar { $.x × 2 }
}
Foo.new(:42x).bar.say; # 84

constant &bar = Foo.^find_method("bar");
say bar Foo.new(:42x); # 84

Now, how to do the constant bit through the MOP, that is something for someone else to beat me to figure that one out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants