-
Notifications
You must be signed in to change notification settings - Fork 578
Adding a try/catch syntax to Perl #18504
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
Comments
Cross-posted to perl5-porters@ at |
Work progresses at pace on this branch: https://github.com/Perl/perl5/tree/leonerd/feature-try In fact at time of writing, it now passes all the unit tests of Once I have that working, I shall have a go at the remaining core tasks which didn't affect a CPAN module - such as B::Deparse support. And then it should be ready for review. Hopefully either by end of weekend, or if not, middle of next week. |
There are two points that the current design (docs and tests) leaves entirely unaddressed. Those are
So far it happens to be the same as eval, but only due to a lazy minimalist implementation that does not take steps differently. I suspect a more complete design may have something to say about these facts. In particular I am tempted by the ideas that
Comments welcome |
Those ideas which tempt you, appeal (seem natural) to me. |
Not invoking Also, how would it interact with code called from the |
I will admit the |
Will the lexical be set the same (dualvar and all) as
This troubles me: fine right up until you need it, but at that point it is difficult or impossible to work around. I think I'd rather see it invoked, but with |
You might be thinking of |
Oops, yes I was. |
For I think |
Righty. In that case I'm happy to accept the wisdom of the crowds on the subject of On the subject of
The use of |
This seems reasonable for an initial implementation. I do think it's important to prevent people from relying on |
Where is ' |
Current plan is to implement it as a phaser: #17949 |
Well, my question was mostly about running existing Edit: it seems from there that |
* Add feature, experimental warning, keyword * Basic parsing * Basic implementation as optree fragment See also #18504
With #18505 now merged, this is partway finished. I don't want to close this issue yet, because much work still needs to be done.
However, the Perl-user visible syntax should now be stable, so as of the next point release (5.33.7) folks should be able to start playing with this under the feature guard |
I've now opened a second PR #18552 to address the concerns listed above. It's purely internals-neatening and should not affect the user-visible syntax or semantics. |
One other thing that turns out already works by coïncidence, though I haven't yet documented or tested, is value semantics (including list valued return) while inside a
I may consider documenting that and adding a unit test, if it's something we feel we should give a guarantee about. |
With #18552 now merged, and additionally the-above semantics about final expression values being documented and tested by 397e6c1 I think I am happy to mark this Issue as complete. The overall For now I think this is good to test in 5.33 and 5.34. :) |
* Add feature, experimental warning, keyword * Basic parsing * Basic implementation as optree fragment See also Perl#18504 # Conflicts: # ext/Opcode/Opcode.pm
I intend to add
try/catch
syntax. This has been one of the most frequently-requested of core syntax features - from both community sources like Freenode #perl and other core developers - so I do not anticipate this will be a contentious or debated idea.As many of the existing CPAN solutions all follow a very similar theme - including my own
Syntax::Keyword::Try
- I expect I shall follow that pattern, and likewise do not anticipate that this will be considered controversial.Syntax::Keyword::Try
has been the preferred module by Freenode #perl for a while now, and folks seem happy with it.I further intend it to be introduced as
Towards this goal, I have created a module
Feature::Compat::Try
to simplify migration. Existing authors canuse Feature::Compat::Try;
in their current code, today, and import a configured version of
Syntax::Keyword::Try
which works on all Perl versions back to 5.16, and conforms exactly to the specification of the thing I want to add to core. (S:K:T additionally contains other features, experimental ideas, and past mistakes, that I do not intend to bring in at this time, hence the configuration).A brief summary, from its synopsis, is:
If anyone wishes to review in more detail the syntax and semantics, please read the documentation and unit-tests of this module. That is what I intend to implement exactly. You do not have to wait until I have a PR to actually implement it to do this - the earlier you do this, the better :)
The text was updated successfully, but these errors were encountered: