# New Ticket Created by yary # Please include the string: [perl #66606] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=66606 >
yary perl6: (my @random_numbers).push: int 10.rand for ^3; say @random_numbers.join: ' '; 12:36 p6eval ..STD_red… 12:36 p6eval ..pugs: OUTPUT«3 4 3» 12:36 p6eval ..rakudo 77f9d7: OUTPUT«Lexical '@random_numbers' not found» 12:37 yary Methinks pugs wins in that statement- anyone think that bug looks familiar? Or should I submit? ...pmichaud rakudo: my @random_numbers; @random_numbers.push( int(10.rand) ) for ^3; say @random_numbers.join(' '); 12:43 p6eval rakudo 77f9d7: OUTPUT«3 3 9» ...12:55 pmichaud it's the declaration of the "my" as modified by the "for" # bug here vvv 12:55 pmichaud rakudo: my $x = 1 for ^3; say $x; 12:55 p6eval rakudo ba09b2: OUTPUT«Lexical '$x' not found» # bug there ^^^ 12:55 pmichaud the "for" modifier is imposing a block on what it modifies. #discussion yary So the next question is, does it make sense for a lexical declaration in an implied block (no curlies) to have a lifetime limited to that implied block? 13:02 PerlJam What does S04 say about it? (if anything) 13:16 pmurias yary: what do you mean by an implied block? 13:17 pmurias yary: generally only curlies introduce a new lexical scope 13:18 pmichaud rakudo: $_ = 'hello'; .say for ^3; say $_; 13:18 p6eval rakudo ba09b2: OUTPUT«012hello» 13:18 pmichaud pmurias: the ".say" has an implied block around it. 13:19 yary Rakudo's behavior suggests that a "for" modifier at the end of a statement which includes a declaration gives a lexical scope to that declaration, and then the variable is invisible outside 13:19 yary sorry for the verbosity 13:20 pmurias yary: verbosity is better then ambiguity 13:21 pmichaud it's very possible that implying a block on the lhs isn't correct, and that we need to be making a temporary $_ or something. 13:22 pmichaud at any rate, the $_ that is used on the lhs of a for modifier isn't the same as the $_. 13:22 pmichaud at any rate, the $_ that is used on the lhs of a for modifier isn't the same as the $_ outside of the for modifier. 13:25 yary That much (about $_) I understand from p5... haven't digested S04 yet, but I'll submit this as a bug for folks to ponder and accept/reject 13:28 pmurias there is a "Remeber, no implicit block scopes." sentence in S04, although in a different context 13:28 pmichaud Yes -- a bit later it talks about the handling of $_ and the for modifier. 13:28 pmichaud It says to get to the outer $_ one uses OUTER::<$_> 13:29 pmichaud which will be a little weird, since it means that OUTER::<$foo> would refer to a different scope from OUTER::<$_> if used inside a for modifier. 13:29 TimToady that's true for any lexical in any lexical scope 13:30 TimToady if $_ is declared internally and $foo externally 13:30 pmichaud TimToady: We're looking at the case of: 13:30 pmichaud say $_ for ^3; 13:30 TimToady yes, I've been thinking about it 13:30 pmichaud okay. 13:30 TimToady the spec only requires a private copy for $_ currently 13:31 pmichaud correct. 13:31 TimToady doesn't require a block 13:31 pmichaud I think the use of a block might've been a Rakudo shortcut. TimToady we could say it is implciit 13:31 TimToady but... 13:31 TimToady we can't really allow $^a to pay attention to implicit {} 13:31 pmichaud interestingly, I'm not sure that it does in Rakudo's case. 13:32 pmichaud rakudo: say $^a for ^3; 13:32 p6eval rakudo ba09b2: OUTPUT«too few arguments passed (0) - 1 params expectedin Main (/tmp/jBX8Gm96fv:0)» 13:32 TimToady well, could use a better error 13:32 pmichaud sure. 13:32 pmichaud rakudo: { say $^a for ^3 }('hello'); 13:32 p6eval rakudo ba09b2: OUTPUT«hellohellohello» 13:32 moritz_ std: say $^a for ^3; 13:32 p6eval std 27084: OUTPUT«ok 00:02 38m» ... TimToady this is also all related to $a ?? my $bar !! my $baz 13:34 TimToady thunks aren't quite blocks etcetera!