Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Perl6 Late variable declaration allowed?

by rir (Vicar)
on Nov 01, 2011 at 18:07 UTC ( #935178=perlquestion: print w/replies, xml ) Need Help??
rir has asked for the wisdom of the Perl Monks concerning the following question:

use v6; say rout(); sub rout { return $var; } my $var = "Hey";
This outputs Any().

Is this correct behavior?

Is there or will there be a uninitialized warning mechanism?

Be well,
rir

Replies are listed 'Best First'.
Re: Perl6 Late variable declaration allowed?
by moritz (Cardinal) on Nov 01, 2011 at 20:22 UTC

    It's a bug in Rakudo that it doesn't reject the program at compile time, because $var isn't declared (yet). It's one of our oldest open bugs.

    Update: It should be noted though that lexical variables are always scoped to a block in Perl 6, and that the detection of of undeclared variables happens only at compile time. Thus this piece of code works differently in Perl 5 and Perl 6 (and this time Rakudo is correct here):

    $ perl -Mstrict -wE 'sub f { say eval q[$x] }; my $x = 5; f' Use of uninitialized value in say at -e line 1. $ perl6 -e 'sub f { say eval q[$x] }; my $x = 5; f' 5 $

    Here the $x is scoped to the whole mainline (which is an implicit block), so an eval sees it at runtime even though the eval comes textually before the declaration of $x.

    Second update: I've fixed the bug, so updating to the latest development version should give the desired behavior.

    The fix is a bit incomplete, but you're now much more unlikely to come across this problem.

Re: Perl6 Late variable declaration allowed?
by zentara (Archbishop) on Nov 01, 2011 at 18:20 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://935178]
Approved by herveus
Front-paged by sparkyichi
help
Chatterbox?
[Lady_Aleena]: cPanel is a sponsor of meta::cpan?
[Lady_Aleena]: The default perl on the version of cPanel my web hosts uses is 5.8.8 which means I am dreadfully behind. I doubt perl 6 will hit my web host in my lifetime.

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2017-05-29 09:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?