-
Notifications
You must be signed in to change notification settings - Fork 567
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
[EXPERIMENT] the lexical topic, my $_ #13172
Comments
From @rjbsLexical topic was introduced in perl 5.10.0. Since then, it has come up mostly my $_; # or the now-gone implicit lexicalization by given # ... many lines ... someroutine(sub { ... $_ ... }); After a number of suggestions to deprecate the feature, it was deprecated That time has been bought, but what will the fix be? We need to understand what would make this feature "salvaged," and then whether -- |
From zefram@fysh.orgRicardo SIGNES wrote:
A conceivable class of fix would be implicit "our $_" on certain I think the situations for which we wanted lexical $_ would be better Relatedly, triggering use of a lexical topicaliser by having "my $_" lmap $t { $t + 1 } @stuff where $t is the topicaliser and the braces are mandatory. Defaulting the lmap { $* + 1 } @stuff This can (and should) be prototyped on CPAN before going anywhere near -zefram |
The RT System itself - Status changed from 'new' to 'open' |
From aaron@priven.comOn Aug 15, 2013, at 6:26 PM, Ricardo SIGNES (via RT) <perlbug-followup@perl.org> wrote:
It seems to me that the problem that lexical $_ attempted to solve is where a called subroutine changes $_, but isn't supposed to. $_ = 'a'; How do you allow some_routine to access $_ only when it is supposed to, but not when it's not? I don't see how you do that without either (a) putting extra code in the calling routine -- something like "call_without_exposing_topic some_routine(@args)" -- which is easy to forget and adds nothing really over the existing "{ local $_; some_routine(@args); }" (b) putting extra code in the called routine -- something like "sub fred { my $_ = get_callers_lexical() ; do_something; }" -- which is, inherently, backwards-incompatible with all existing library code. DWIM is great, but not when the computer has to be psychic. So, the only way I can see to solve this problem is to create a new topic variable -- I'll call it $^_ but, you know, call it whatever you want -- that has to be either explicitly passed or explicitly taken, or both. use feature 'lextopic'; $^_ = "Something\n"; sub new_routine { use old_library ('old_routine'); If you don't either do "topicalize" or "callertopic", it defaults to *not* allowing access to the topic, which is safer than defaulting *to* sharing the topic, as global $_ does. (I think $^_ might be a good name for the alternative topic variable, but I'm pretty sure callertopic and topicalize are the wrong names.) I think that would work to solve the "this subroutine accidentally clobbered my $_" problem. I suspect the cure is worse than the disease. -- -- |
From @ikegamiIsn't the lack of localisation in C<< while (<$fh>) >> the true problem? |
From friedberg@exs.esb.comIsn't this
what DWIM really requires? ROFLMAO (from a lurker) Carl Friedberg From: Aaron Priven [mailto:aaron@priven.com] On Aug 15, 2013, at 6:26 PM, Ricardo SIGNES (via RT) <perlbug-followup@perl.org<mailto:perlbug-followup@perl.org>> wrote: We need to understand what would make this feature "salvaged," and then whether It seems to me that the problem that lexical $_ attempted to solve is where a called subroutine changes $_, but isn't supposed to. $_ = 'a'; How do you allow some_routine to access $_ only when it is supposed to, but not when it's not? I don't see how you do that without either (a) putting extra code in the calling routine -- something like "call_without_exposing_topic some_routine(@args)" -- which is easy to forget and adds nothing really over the existing "{ local $_; some_routine(@args); }" (b) putting extra code in the called routine -- something like "sub fred { my $_ = get_callers_lexical() ; do_something; }" -- which is, inherently, backwards-incompatible with all existing library code. DWIM is great, but not when the computer has to be psychic. So, the only way I can see to solve this problem is to create a new topic variable -- I'll call it $^_ but, you know, call it whatever you want -- that has to be either explicitly passed or explicitly taken, or both. use feature 'lextopic'; $^_ = "Something\n"; sub new_routine { use old_library ('old_routine'); If you don't either do "topicalize" or "callertopic", it defaults to *not* allowing access to the topic, which is safer than defaulting *to* sharing the topic, as global $_ does. (I think $^_ might be a good name for the alternative topic variable, but I'm pretty sure callertopic and topicalize are the wrong names.) I think that would work to solve the "this subroutine accidentally clobbered my $_" problem. I suspect the cure is worse than the disease. -- |
From @cpansproutThis feature was removed in perl 5.24.0. -- Father Chrysostomos |
@cpansprout - Status changed from 'open' to 'rejected' |
Migrated from rt.perl.org#119315 (status was 'rejected')
Searchable as RT119315$
The text was updated successfully, but these errors were encountered: