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

Binding to state variable silently fails #6162

Open
p6rt opened this issue Mar 22, 2017 · 3 comments
Open

Binding to state variable silently fails #6162

p6rt opened this issue Mar 22, 2017 · 3 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Mar 22, 2017

Migrated from rt.perl.org#131043 (status was 'open')

Searchable as RT131043$

@p6rt
Copy link
Author

p6rt commented Mar 22, 2017

From @zoffixznet

  $ 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);

@p6rt
Copy link
Author

p6rt commented Mar 22, 2017

From @geekosaur

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 @&#8203;found;
    for $^v\.pairs \{
        my $value  := \.value;
        state $max = $value;
        my $cmp;
        nqp&#8203;::if\(
            nqp&#8203;::iseq\_i\( \($cmp := $value cmp $max\), 1 \),

            \#\#\# CHANGING FROM $max := to $max = BELOW CHANGES RESULT
            nqp&#8203;::stmts\(\(@&#8203;found = $\_\), \($max := $value\)\),
            nqp&#8203;::if\(
                nqp&#8203;::iseq\_i\($cmp, 0\),
                @&#8203;found\.push&#8203;: $\_
            \)
        \)
    \}
    @&#8203;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

@p6rt
Copy link
Author

p6rt commented Mar 22, 2017

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

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant