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

Some sort of a scoping bug when variables are used inside a closure in a &sub.wrap call in Rakudo #1309

Closed
p6rt opened this issue Sep 23, 2009 · 5 comments

Comments

@p6rt
Copy link

p6rt commented Sep 23, 2009

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

Searchable as RT69312$

@p6rt
Copy link
Author

p6rt commented Sep 23, 2009

From @masak

<masak> rakudo​: sub foo { say "=" x 40 }; for reverse ^40 -> $n {
&foo.wrap({ say "=" x $n; callsame; say "=" x $n }); }; foo
<p6eval> rakudo 0eaf62​:
  OUTPUT«␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤========================================␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤»
<masak> in the above code, why doesn't $n bind like I think it should?
<masak> I had hoped it would produce a nice triangle of ='s.
<pmurias> rakudo​: sub foo { say 40 }; for reverse ^40 -> $n { say
$n;&foo.wrap({ say
  $n; callsame; say $n }); }; foo
<p6eval> rakudo 0eaf62​:
  OUTPUT«39␤38␤37␤36␤35␤34␤33␤32␤31␤30␤29␤28␤27␤26␤25␤24␤23␤22␤21␤20␤19␤18␤17␤16␤15␤14␤13␤12␤11␤10␤9␤8␤7␤6␤5␤4␤3␤2␤1␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤40␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0
<pmurias> masak​: looks like some sort of a scoping bug
* masak submits rakudobug

I'm not certain this is a bug. But if Perl 6 doesn't conform to my
expectations in the above case, it'll be interesting to learn why not.

@p6rt
Copy link
Author

p6rt commented Jan 13, 2012

From @jnthn

On Wed Sep 23 03​:14​:06 2009, masak wrote​:

<masak> rakudo​: sub foo { say "=" x 40 }; for reverse ^40 -> $n {
&foo.wrap({ say "=" x $n; callsame; say "=" x $n }); }; foo
<p6eval> rakudo 0eaf62​:

OUTPUT«␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤========================================␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤␤»

<masak> in the above code, why doesn't $n bind like I think it should?
<masak> I had hoped it would produce a nice triangle of ='s.
<pmurias> rakudo​: sub foo { say 40 }; for reverse ^40 -> $n { say
$n;&foo.wrap({ say
$n; callsame; say $n }); }; foo
<p6eval> rakudo 0eaf62​:

OUTPUT«39␤38␤37␤36␤35␤34␤33␤32␤31␤30␤29␤28␤27␤26␤25␤24␤23␤22␤21␤20␤19␤18␤17␤16␤15␤14␤13␤12␤11␤10␤9␤8␤7␤6␤5␤4␤3␤2␤1␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤40␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0␤0

<pmurias> masak​: looks like some sort of a scoping bug
* masak submits rakudobug

I'm not certain this is a bug. But if Perl 6 doesn't conform to my
expectations in the above case, it'll be interesting to learn why not.

Now it makes you a nice triangle​:

sub foo { say "=" x 40 }; for reverse ^40 -> $n { &foo.wrap({ say "="
x $n; callsame; say "=" x $n }); }; foo

=

===

=====

=======

=========

===========

=============

===============

=================

===================

=====================

=======================

=========================

===========================

=============================

===============================

=================================

===================================

=====================================

=======================================

=======================================

=====================================

===================================

=================================

===============================

=============================

===========================

=========================

=======================

=====================

===================

=================

===============

=============

===========

=========

=======

=====

===

=

Tagging as "testneeded".

/jnthn

@p6rt
Copy link
Author

p6rt commented Jan 13, 2012

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

@p6rt
Copy link
Author

p6rt commented Feb 1, 2012

From @moritz

Now tested in S06-advanced/wrap.t

@p6rt
Copy link
Author

p6rt commented Feb 1, 2012

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

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