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

Support my method syntax #22940

Open
wants to merge 3 commits into
base: blead
Choose a base branch
from
Open

Support my method syntax #22940

wants to merge 3 commits into from

Conversation

leonerd
Copy link
Contributor

@leonerd leonerd commented Jan 23, 2025

This came to light in discussions of Perl/PPCs#68 that my method doesn't actually parse as it should. This PR adds that.

Admittedly this syntax isn't all that useful without the corresponding ->&, so I'm happy to defer merging this until we can implement both at once. That way we'd avoid recommending to people the "just call it like a regular sub" workaround; as longterm we might not like that idea anyway.


  • This set of changes requires a perldelta entry, and it is included.

@@ -185,6 +185,26 @@ Just like regular subroutines, methods I<can> be anonymous:
}
}

Methods can also be declared as lexical subroutines, using the C<my> prefix.
This creates a subroutine that is lexically visible within the current scope,
but does not appear in the symbol table. This creates the effect of a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: You have two sentences in a row which start with "This creates...." I suggest rephrasing one of them.

P.S. This is a great addition. Thanks, @leonerd.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahyes; given it a slight edit.

@ivrntsv
Copy link

ivrntsv commented Jan 28, 2025

I guess it's a nitpicking, but nonetheless. Should it be state method? I suppose my method as my sub is redefind on each block execution. It doesn't matter in file scope executed once, but even in that case I prefer state sub version to not get bitten by habit in block scope (ofcourse not when I really need my sub as a closure, for example). Maybe there should be my and state methods. Or my method semantics is different from my sub and similar to state sub?

@haarg
Copy link
Contributor

haarg commented Jan 28, 2025

state sub and our sub already exist, so state method and our method should probably also exist.

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

Successfully merging this pull request may close these issues.

5 participants