Search code examples
rakulexical-scopedynamic-scope

Why doesn't temp work in Perl 6 core settings?


I was looking in and saw this comment in the indir implementation:

sub indir(Str() $path, $what, :$test = <r w>) {
    my $newCWD := $*CWD.chdir($path,:$test);
    $newCWD // $newCWD.throw;

    {
        my $*CWD = $newCWD;  # temp doesn't work in core settings :-(
        $what();
    }
}

I thought this use of my was strange, which led to doc issue #1082 niggling about if my is actually lexical. I would have thought that temp would be more appropriate for user-level temporary changes to dynamic variables.

But now, I see this comment, but I'm not quite sure what it means. Is temp broken this deep? Is it not available here? Or is the comment just wrong?

If the comment is right, has this way of dealing with dynamic variables leaked up to the everyday programmer level because that is what some people have to do in the guts (and they got used to that?)

And, how low-level is this level really? It seems like all of Perl 6 should be available here.


Solution

  • Perhaps the comment in the source code would be less misleading if it was:

    # temp $*CWD doesn't work in core settings (which we're in)
    # my $*CWD = ... is a decent workaround in this case :)
    

    It seems like all of Perl 6 should be available here.

    Full Perl 6 must wait until after completion of compilation of the Perl 6 CORE setting. This corresponds to the Rakudo Perl 6 compiler's "core" src tree. This includes the code with the "# temp doesn't work in core settings :-(" comment.