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

Statmenet modifier's "implied" lexical scope hides my declaration #1062

Closed
p6rt opened this issue Jun 15, 2009 · 7 comments
Closed

Statmenet modifier's "implied" lexical scope hides my declaration #1062

p6rt opened this issue Jun 15, 2009 · 7 comments

Comments

@p6rt
Copy link

p6rt commented Jun 15, 2009

Migrated from rt.perl.org#66606 (status was 'resolved')

Searchable as RT66606$

@p6rt
Copy link
Author

p6rt commented Jun 15, 2009

From not.com@gmail.com

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«0â�¤1â�¤2â�¤helloâ�¤Â»
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 expectedâ�¤in 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«helloâ�¤helloâ�¤helloâ�¤Â»
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!

@p6rt
Copy link
Author

p6rt commented Jun 16, 2009

From @TimToady

We now spec a simple temporization (doesn't even have to be implemented
using "temp") for topicalizing statement modifiers. See latest S04.

Larry

@p6rt
Copy link
Author

p6rt commented Jun 16, 2009

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Aug 13, 2010

From sohtil@gmail.com

Seems to work in current Rakudo​:

$ ./perl6

my $x = 1 for ^3; say $x;
1
(my @​random_numbers).push​: 10.rand for ^3; say @​random_numbers.join​: ' ';
8.57698486457718 7.87678365219968 5.21120179805695
(my @​a).push​: $_ for ^3; say @​a;
012

This is Rakudo Perl 6, version 2010.07-113-gc41bcd7 built on parrot
2.6.0 r48341

@p6rt
Copy link
Author

p6rt commented Sep 14, 2011

From @jnthn

On Fri Aug 13 13​:36​:18 2010, lithos wrote​:

Seems to work in current Rakudo​:

$ ./perl6

my $x = 1 for ^3; say $x;
1
(my @​random_numbers).push​: 10.rand for ^3; say @​random_numbers.join​:
' ';
8.57698486457718 7.87678365219968 5.21120179805695
(my @​a).push​: $_ for ^3; say @​a;
012

This is Rakudo Perl 6, version 2010.07-113-gc41bcd7 built on parrot
2.6.0 r48341

Yup, today too​:

my $x = 1 for ^3; say $x;
1
(my @​random_numbers).push​: 10.rand for ^3; say @​random_numbers.join​: ' ';
0.959232485192878 8.2035429598497 1.59194767513451
(my @​a).push​: $_ for ^3; say @​a;
0 1 2

Just needs tests; tagging testneeded.

/jnthn

@p6rt
Copy link
Author

p6rt commented Sep 14, 2011

From @tadzik

On Wed Sep 14 14​:03​:21 2011, jnthn@​jnthn.net wrote​:

Just needs tests; tagging testneeded.
Tests added in Raku/roast@bb87d9718f

@p6rt
Copy link
Author

p6rt commented Sep 14, 2011

@jnthn - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Sep 14, 2011
@p6rt p6rt added the testneeded label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant