Open p6rt opened 7 years ago
$ perl6 -v
This is Rakudo version 2017.03-20-g027aa54 built on MoarVM version 2017.03-7-g029d121
implementing Perl 6.c.
$ perl6 -e 'state $x = 42; dd $x'
Int $x = 42
$ perl6 -e 'state $x := 42; dd $x'
Mu
I also have a small snippet where the `state` declaration uses assignment, but later in the code a binding is used for the same variable. The result of the routine changes, based on whether it's a binding or an assignment (also, I believe the result with binding is incorrect:
use MONKEY;
sub z {
my @found;
for $^v.pairs {
my $value := .value;
state $max = $value;
my $cmp;
nqp::if(
nqp::iseq_i( ($cmp := $value cmp $max), 1 ),
### CHANGING FROM $max := to $max = BELOW CHANGES RESULT
nqp::stmts((@found = $_), ($max := $value)),
nqp::if(
nqp::iseq_i($cmp, 0),
@found.push: $_
)
)
}
@found.List
}
dd z (1, 2, 65, -6, 4);
I can't help but think that binding a state variable should be illegal, and doing so will have unexpected effects.
On Wed, Mar 22, 2017 at 1:48 PM, Zoffix Znet \perl6\-bugs\-followup@​perl\.org wrote:
# New Ticket Created by Zoffix Znet # Please include the string: [perl #131043] # in the subject line of all future correspondence about this issue. # \<URL: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=131043 >
$ perl6 \-v This is Rakudo version 2017\.03\-20\-g027aa54 built on MoarVM version
2017.03-7-g029d121 implementing Perl 6.c.
$ perl6 \-e 'state $x = 42; dd $x' Int $x = 42 $ perl6 \-e 'state $x := 42; dd $x' Mu
I also have a small snippet where the `state` declaration uses assignment, but later in the code a binding is used for the same variable. The result of the routine changes, based on whether it's a binding or an assignment (also, I believe the result with binding is incorrect:
use MONKEY; sub z \{ my @​found; for $^v\.pairs \{ my $value := \.value; state $max = $value; my $cmp; nqp​::if\( nqp​::iseq\_i\( \($cmp := $value cmp $max\), 1 \), \#\#\# CHANGING FROM $max := to $max = BELOW CHANGES RESULT nqp​::stmts\(\(@​found = $\_\), \($max := $value\)\), nqp​::if\( nqp​::iseq\_i\($cmp, 0\), @​found\.push​: $\_ \) \) \} @​found\.List \} dd z \(1, 2, 65, \-6, 4\);
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
The RT System itself - Status changed from 'new' to 'open'
Migrated from rt.perl.org#131043 (status was 'open')
Searchable as RT131043$