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

Contradictory sentence for temp #1085

Closed
briandfoy opened this issue Dec 27, 2016 · 7 comments
Closed

Contradictory sentence for temp #1085

briandfoy opened this issue Dec 27, 2016 · 7 comments
Assignees
Labels
docs Documentation issue (primary issue type)

Comments

@briandfoy
Copy link
Contributor

The temp docs seems to say opposite things about resetting values:

"temporizes" the variable passed as the argument, which means it is reset to its old value on scope exit. (This is similar to the local operator in Perl 5, except that temp does not reset the value).

In the first sentence it says it "reset[s]", but the second says "does not reset". Perhaps there's some other distinction intended.

@briandfoy briandfoy added the docs Documentation issue (primary issue type) label Dec 27, 2016
@coke
Copy link
Collaborator

coke commented Dec 28, 2016

The reference to Perl 5 should be removed here; those belong in the 5-to-6 documents if anywhere.

The value is reset:

my $a = "three";
say $a;
{
    temp $a = "four";
    say $a;
}
say $a;

outputs

three
four
three

@coke coke closed this as completed in 7b663ba Dec 28, 2016
@ronaldxs
Copy link
Contributor

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:

Perl 6 and temp example ..........
new scope but before temp: three
temp but not initialized: three
set in temp scope: four
reset after temp scope: three
Perl 5 and local parallel example ..........
new scope but before local: three
local and reset but not initialized: uninit 2
set in local scope: four
reset after local scope: three

The "other distinction intended" was between
temp but not initialized: three
and
local and reset but not initialized: uninit 2

@ronaldxs ronaldxs reopened this Dec 28, 2016
@coke coke self-assigned this Dec 28, 2016
@coke coke closed this as completed in b44666b Dec 28, 2016
@coke
Copy link
Collaborator

coke commented Dec 28, 2016

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

@briandfoy
Copy link
Contributor Author

briandfoy commented Dec 28, 2016 via email

@briandfoy briandfoy reopened this Dec 28, 2016
@coke
Copy link
Collaborator

coke commented Dec 28, 2016

@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?

@coke
Copy link
Collaborator

coke commented Jan 1, 2017

I'll close this in the next few days if I don't hear any more feedback about what's the remaining issue is.

@briandfoy
Copy link
Contributor Author

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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation issue (primary issue type)
Projects
None yet
Development

No branches or pull requests

3 participants