FAQ
In Rakudo right now, this lives: "{$foo;$^foo}(1)"

However, the spec test expects it to die during compilation (see the
end of S06-signature/positional-placeholders.t). It says, "A
non-twigil variable should not precede a corresponding twigil
variable."

In Rakudo right now, this says 3: sub foo { my $a = 3; say $^a };
foo(5); # RT #64310

The spec test would seem to imply that this should die during the
definition of 'foo'.

On the other hand, if we swap the statements, it merely complains that
$a is redeclared and then croaks because we assigned to a read-only
variable.

sub foo { say $^a; my $a = 3 }; foo(5);
Redeclaration of variable $a
5
Cannot assign to readonly variable.

What's right here? Should we die when defining a block or sub with a
variable before a placeholder of the same name?

Kyle.

Search Discussions

  • Patrick R. Michaud at Jul 30, 2009 at 4:02 pm

    On Thu, Jul 30, 2009 at 10:29:04AM -0500, Kyle Hasselbacher wrote:
    In Rakudo right now, this lives: "{$foo;$^foo}(1)"

    However, the spec test expects it to die during compilation (see the
    end of S06-signature/positional-placeholders.t). It says, "A
    non-twigil variable should not precede a corresponding twigil
    variable."
    The spec is correct. Rakudo currently has some issues with
    order-of-lexicals declarations.

    In Rakudo right now, this says 3: sub foo { my $a = 3; say $^a };
    foo(5); # RT #64310
    The spec test would seem to imply that this should die during the
    definition of 'foo'.
    Rakudo should complain about the placeholder attempting to redefine $^a.
    I don't know if that elevates to the level of "die", though; STD.pm
    seems to treat it as a "potential difficulty".
    On the other hand, if we swap the statements, it merely complains that
    $a is redeclared and then croaks because we assigned to a read-only
    variable.

    sub foo { say $^a; my $a = 3 }; foo(5);
    Redeclaration of variable $a
    5
    Cannot assign to readonly variable.
    Rakudo is correct that it's a redeclaration and that the
    variable (parameter) is readonly and cannot be assigned to.

    Pm

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl6-language @
categoriesperl
postedJul 30, '09 at 3:29p
activeJul 30, '09 at 4:02p
posts2
users2
websiteperl6.org

People

Translate

site design / logo © 2021 Grokbase