# New Ticket Created by  Larry Wall 
# Please include the string:  [perl #126415]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=126415 >


Using a normal closure works:

lucca:~/rc 1244> cat foo
my @isprime = False,False;   # 0 and 1 are not prime by definition

say (for 1 .. 10 -> $i {
    $i if @isprime[$i] //= so $i %% none 2 ...^ { $_ > $i.sqrt.floor };
})
lucca:~/rc 1245> p foo
(2 3 5 7)

Using  a WhateverCode doesn't work:

lucca:~/rc 1246> cat bar
my @isprime = False,False;   # 0 and 1 are not prime by definition

say (for 1 .. 10 -> $i {
    $i if @isprime[$i] //= so $i %% none 2 ...^ * > $i.sqrt.floor;
})
lucca:~/rc 1247> p bar
(2 3 4 5 6 7 8 9 10)

But it works again if we expand out the //= to its desugar:

lucca:~/rc 1250> cat baz
my @isprime = False,False;   # 0 and 1 are not prime by definition

say (for 1 .. 10 -> $i {
    $i if @isprime[$i] = @isprime[$i] // so $i %% none 2 ...^ * >
$i.sqrt.floor;
})
lucca:~/rc 1251> p baz
(2 3 5 7)

Reply via email to