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

Interaction of dynamic variables and process-state needs to be specced #14

Closed
moritz opened this issue Jul 5, 2012 · 2 comments
Closed

Comments

@moritz
Copy link
Contributor

moritz commented Jul 5, 2012

There are several special variables like %*ENV, $*PID, %*SIG, $*PROGRAM_NAME which from the outside of a UNIX process affect the whole program, but inside of Perl 6 they are scoped dynamically.

So, what happens when such a dynamic variable is redefined? Does the new variable loose its special association with the process?
Consider

my @list := gather loop {
    take my $*PROGRAM_NAME = 'a'..'z'.roll(5)
}
.say for @list;

(in Perl 5, $0 is assignable and changes the program name as reported by ps aux, and I expect the same to be true for Perl 6).

Does the program name change every single time @list is being reified?
If yes, how could that be implemented in an efficient manner that doesn't affect all control flow?
If not, what's the point of having those variables dynamically scoped?

@sorear
Copy link
Contributor

sorear commented Jul 5, 2012

What I seem to recall from past conversations with @TimToady is that once upon a time, there were two forms - $*VAR for global variables and $+VAR for dynamically scoped variables, or maybe the other way around. Then somebody noticed that global scope was just a special case of dynamic scope, and the two concepts were merged.

My opinion here is that my $*PROGRAM_NAME is probably wrong, and if you want to change the reported program name, it would be better to use temp $*PROGRAM_NAME = .... Maybe it would make sense to reintroduce a distinction between names that it makes sense to override with my, and names that don't.

@TimToady
Copy link
Contributor

There is already a name distinction; you may use PROCESS:: to refer to the process-wide variant. The dynamic variants are useful for programs that want to lie to themselves in a dynamic scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants