-
Notifications
You must be signed in to change notification settings - Fork 293
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
Contradictory sentence for temp #1085
Comments
The reference to Perl 5 should be removed here; those belong in the 5-to-6 documents if anywhere. The value is reset:
outputs
|
There is "some other distinction intended" and it should be documented someplace. I am not even clear on it being documented in the wrong place. Example below should explain. Will drop by IRC later if can't be cleared up here. #!/usr/bin/env perl6
say 'Perl 6 and temp example ', '.' x 10;
my $a = "three";
sub f {
say "new scope but before temp: ", $a // "uninit 1";
temp $a;
say "temp but not initialized: ", $a // "uninit 2";
$a = "four";
say "set in temp scope: $a"
}
f();
say "reset after temp scope: $a";
use Inline::Perl5;
Inline::Perl5.new.run(q:to/PERL5/);
use strict;
use warnings;
use feature 'say';
use vars q/$a/;
# my $a; # generates error : "Can't localize lexical variable ..."
say 'Perl 5 and local parallel example ', '.' x 10;
sub f {
say "new scope but before local: ", $a // "uninit 1";
local $a;
say "local and reset but not initialized: ", $a // "uninit 2";
$a = "four";
say "set in local scope: $a"
}
$a = "three";
f();
say "reset after local scope: $a";
PERL5 Output:
The "other distinction intended" was between |
Ah. And that explains the original confusing resets/doesn't reset - one was scope exit, one was when invoking 'temp'. Thanks for clearing that up, @ronaldxs |
I think there's still a problem. In doc/Language/5to6-perlfunc.pod6 it talks about not resetting, and in the doc/Language/operators.pod6 it doesn't. I think the change left out most of the nuance shown in this issue. The docs still say it resets the variable without the exception Ronald noted.
|
@briandfoy - there's no reason to talk about how Perl 6 isn't like Perl 5 in the main docs; that's explicitly why we have the 5to6 docs. I think my latest stab at the docs show exactly the fact that temp itself doesn't reset the value until it is set. (edited for clarity) ""temporizes" the variable passed as the argument. The variable begins with the same value as it had in the outer scope, but can be assigned new values in this scope. Upon exiting the scope, the variable will be restored to its original value." What specifically from @ronaldxs 's Perl 6 sample is missing here? |
I'll close this in the next few days if I don't hear any more feedback about what's the remaining issue is. |
I think the phrase with "unset" in the 5to6 docs is weird. The phrase after it about keeping its original value should suffice. Otherwise this looks good. Thanks, |
The temp docs seems to say opposite things about resetting values:
In the first sentence it says it "reset[s]", but the second says "does not reset". Perhaps there's some other distinction intended.
The text was updated successfully, but these errors were encountered: