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

FIRST doesn't see lexicals from surrounding block #3146

Closed
p6rt opened this issue May 26, 2013 · 6 comments
Closed

FIRST doesn't see lexicals from surrounding block #3146

p6rt opened this issue May 26, 2013 · 6 comments

Comments

@p6rt
Copy link

p6rt commented May 26, 2013

Migrated from rt.perl.org#118179 (status was 'rejected')

Searchable as RT118179$

@p6rt
Copy link
Author

p6rt commented May 26, 2013

From @coke

23​:54 < [Coke]> r​: for 1..10 { my $a = 3; FIRST { say $a} }
23​:54 <+camelia> rakudo 45ae2d​: OUTPUT«(Any)␤»

I would expect that to output "3".

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented May 26, 2013

From @pmichaud

On Sat May 25 21​:13​:26 2013, coke wrote​:

23​:54 < [Coke]> r​: for 1..10 { my $a = 3; FIRST { say $a} }
23​:54 <+camelia> rakudo 45ae2d​: OUTPUT«(Any)␤»

I would expect that to output "3".

Since the FIRST block is invoked before the assignment/initialization,
the output of "Any" seems correct.

For example​:

  > for 1..5 { my $a; FIRST { $a = 3 }; say $a }
  3
  (Any)
  (Any)
  (Any)
  (Any)
  >

Thus the FIRST block sees the correct lexical $a... it's just executing
before the initialization.

Pm

@p6rt
Copy link
Author

p6rt commented May 26, 2013

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

@p6rt
Copy link
Author

p6rt commented May 26, 2013

From @coke

On Sat May 25 22​:32​:15 2013, pmichaud wrote​:

On Sat May 25 21​:13​:26 2013, coke wrote​:

23​:54 < [Coke]> r​: for 1..10 { my $a = 3; FIRST { say $a} }
23​:54 <+camelia> rakudo 45ae2d​: OUTPUT«(Any)␤»

I would expect that to output "3".

Since the FIRST block is invoked before the assignment/initialization,
the output of "Any" seems correct.

For example​:

> for 1\.\.5 \{ my $a; FIRST \{ $a = 3 \}; say $a \}
3
\(Any\)
\(Any\)
\(Any\)
\(Any\)
> 

Thus the FIRST block sees the correct lexical $a... it's just executing
before the initialization.

Pm

Spec agress with you​: "at loop initialization time, before any ENTER"

I expected it to mean "the FIRST time a block is executed".

My workaround was to use a lexical to track if it was the first time through the loop or not;
will stick with that.

Sadly, Rejecting ticket.

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented May 26, 2013

@coke - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this as completed May 26, 2013
@p6rt
Copy link
Author

p6rt commented May 26, 2013

From @masak

coke (>)​:

I expected it to mean "the FIRST time a block is executed".

My workaround was to use a lexical to track if it was the first time
through the loop or not;
will stick with that.

<masak> [Coke]​: doesn't START do exactly what you wanted from FIRST?
<masak> r​: for 1..10 { my $a = 3; START { say $a } }
<camelia> rakudo 0e206e​: OUTPUT«3␤»
* masak adds this to #​118179

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant