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 and ->&meth syntax #22940

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

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.

This also adds the corresponding ->& as discussed in PPC0033.


  • 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.

@leonerd leonerd force-pushed the my-method branch 2 times, most recently from b6cf6c1 to ac3df73 Compare February 5, 2025 17:19
@leonerd leonerd changed the title Support my method syntax Support my method and ->&meth syntax Feb 6, 2025
@leonerd
Copy link
Contributor Author

leonerd commented Feb 6, 2025

Further work to add support for the ->& operator to invoke lexical subs as methods. Currently still lacking documentation, which I shall work on today.

@leonerd leonerd added the squash-before-merge Author must squash the commits down before merging to blead label Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
squash-before-merge Author must squash the commits down before merging to blead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants