[perl #130859] [WEIRD] WhateverCode subscript inside WhateverCode inside block doesn't properly close over lexical

2018-02-04 Thread Zoffix Znet via RT
On Sat, 25 Feb 2017 06:55:02 -0800, sml...@gmail.com wrote:
> A WhateverCode containing an array subscript that is itself a
> WhateverCode, usually works fine... e.g. `*.[*-1]` always returns the
> last positional element of its argument.
> 
> A WhateverCode closing over a lexical variable usually works fine,
> e.g. `* - $x` always subtracts the *current* value of $x from its
> argument.
> 
> But when *both* of those features are combined, *and* the variable
> that is closed over is scoped to an outer block or routine that is
> called repeatedly, then it misbehaves:
> 
> sub f { my $x = ++$; (*.[* - $x])() }
> say (f,f,f);# (c c c)
> 
> The same, using `map`:
> 
> say (1..3).map: { (*.[* - $_])() };  # (c c c)
> 
> The expected output would be `(c b a)`. For some reason, it seems to
> use the first value of `$x` or `$_` for all three iterations.
> 
> --
> 
> Demonstration that the particular circumstances described above have
> to align for the bug to appear:
> 
> 1) If the WhateverCode subscript is replaced with a static expression,
> the bug disappears:
> 
> say (1..3).map: { (*.[3 - $_])() };  # (c b a)
> 
> 2) If the outer WhateverCode is removed by "inlining" it, the bug
> disappears:
> 
> say (1..3).map: { [* - $_] };# (c b a)
> 
> 3) If the `map` is unrolled so that there is no outer block that gets
> re-entered between invocations of the WhateverCode's, the bug
> disappears:
> 
> my  = *.[* - $_];
> $_ = 1; say f ;  # c
> $_ = 2; say f ;  # b
> $_ = 3; say f ;  # a
> 
> --
> This is Rakudo version 2017.02-95-g0be724727 built on MoarVM version
> 2017.02-7-g3d859008 implementing Perl 6.c.


Thank you for the report. This is now fixed.

Fix:  https://github.com/rakudo/rakudo/commit/e8c6c259ce72fb5
Test: https://github.com/perl6/roast/commit/501f51b56c77fec06


[perl #130859] [WEIRD] WhateverCode subscript inside WhateverCode inside block doesn't properly close over lexical

2018-02-04 Thread Zoffix Znet via RT
On Sat, 25 Feb 2017 06:55:02 -0800, sml...@gmail.com wrote:
> A WhateverCode containing an array subscript that is itself a
> WhateverCode, usually works fine... e.g. `*.[*-1]` always returns the
> last positional element of its argument.
> 
> A WhateverCode closing over a lexical variable usually works fine,
> e.g. `* - $x` always subtracts the *current* value of $x from its
> argument.
> 
> But when *both* of those features are combined, *and* the variable
> that is closed over is scoped to an outer block or routine that is
> called repeatedly, then it misbehaves:
> 
> sub f { my $x = ++$; (*.[* - $x])() }
> say (f,f,f);# (c c c)
> 
> The same, using `map`:
> 
> say (1..3).map: { (*.[* - $_])() };  # (c c c)
> 
> The expected output would be `(c b a)`. For some reason, it seems to
> use the first value of `$x` or `$_` for all three iterations.
> 
> --
> 
> Demonstration that the particular circumstances described above have
> to align for the bug to appear:
> 
> 1) If the WhateverCode subscript is replaced with a static expression,
> the bug disappears:
> 
> say (1..3).map: { (*.[3 - $_])() };  # (c b a)
> 
> 2) If the outer WhateverCode is removed by "inlining" it, the bug
> disappears:
> 
> say (1..3).map: { [* - $_] };# (c b a)
> 
> 3) If the `map` is unrolled so that there is no outer block that gets
> re-entered between invocations of the WhateverCode's, the bug
> disappears:
> 
> my  = *.[* - $_];
> $_ = 1; say f ;  # c
> $_ = 2; say f ;  # b
> $_ = 3; say f ;  # a
> 
> --
> This is Rakudo version 2017.02-95-g0be724727 built on MoarVM version
> 2017.02-7-g3d859008 implementing Perl 6.c.


Thank you for the report. This is now fixed.

Fix:  https://github.com/rakudo/rakudo/commit/e8c6c259ce72fb5
Test: https://github.com/perl6/roast/commit/501f51b56c77fec06



[perl #130859] [WEIRD] WhateverCode subscript inside WhateverCode inside block doesn't properly close over lexical

2017-02-25 Thread via RT
# New Ticket Created by  Sam S. 
# Please include the string:  [perl #130859]
# in the subject line of all future correspondence about this issue. 
# https://rt.perl.org/Ticket/Display.html?id=130859 >


A WhateverCode containing an array subscript that is itself a
WhateverCode, usually works fine... e.g. `*.[*-1]` always returns the
last positional element of its argument.

A WhateverCode closing over a lexical variable usually works fine,
e.g. `* - $x` always subtracts the *current* value of $x from its
argument.

But when *both* of those features are combined, *and* the variable
that is closed over is scoped to an outer block or routine that is
called repeatedly, then it misbehaves:

sub f { my $x = ++$; (*.[* - $x])() }
say (f,f,f);# (c c c)

The same, using `map`:

say (1..3).map: { (*.[* - $_])() };  # (c c c)

The expected output would be `(c b a)`. For some reason, it seems to
use the first value of `$x` or `$_` for all three iterations.

--

Demonstration that the particular circumstances described above have
to align for the bug to appear:

1) If the WhateverCode subscript is replaced with a static expression,
the bug disappears:

say (1..3).map: { (*.[3 - $_])() };  # (c b a)

2) If the outer WhateverCode is removed by "inlining" it, the bug disappears:

say (1..3).map: { [* - $_] };# (c b a)

3) If the `map` is unrolled so that there is no outer block that gets
re-entered between invocations of the WhateverCode's, the bug
disappears:

my  = *.[* - $_];
$_ = 1; say f ;  # c
$_ = 2; say f ;  # b
$_ = 3; say f ;  # a

--
This is Rakudo version 2017.02-95-g0be724727 built on MoarVM version
2017.02-7-g3d859008 implementing Perl 6.c.