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

`$++` statements in routines sometimes give the anonymous variable `my` scoping, sometimes `state` scoping in Rakudo #3566

Open
p6rt opened this issue Oct 26, 2014 · 4 comments
Labels
Bug

Comments

@p6rt
Copy link

@p6rt p6rt commented Oct 26, 2014

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

Searchable as RT123060$

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Oct 26, 2014

From @masak

<masak> is there a recent spec commit for `$` in non-signature use? I
can't seem to find it by skimming the spec log.
<masak> ISTR it being this year, so I shouldn't even have to look that far back.
<masak> ah, found this​:
rakudo/rakudo@ce26312
<masak> that one only *speculates* that the semantics be `state $`, though.
<masak> I haven't found a spec or decision about it.
<masak> right now the semantics seems to be `my`...
<masak> m​: sub foo { ($ = "A")++ }; say foo for ^5
<camelia> rakudo-moar 315ec6​: OUTPUT«A␤A␤A␤A␤A␤»
<lizmat> m​: sub a { $++ }; say a; say a # I think that's state by default
<camelia> rakudo-moar 315ec6​: OUTPUT«0␤1␤»
<masak> waitwait
<masak> lizmat​: how is yours qualitatively different from mine?
<lizmat> not by much
<masak> the only difference I see is the assignment.
<masak> and yet they have different behaviors. o.O
<lizmat> I'd say, yours is NYI
* masak submits rakudobug
<masak> something is *very* fishy there.
<lizmat> m​: sub foo { ($ = 0)++ }; say foo for ^5
<camelia> rakudo-moar 315ec6​: OUTPUT«0␤0␤0␤0␤0␤»
<vendethiel> masak​: it's my $; not state $
<vendethiel> (bare $ is, I mean)
<masak> vendethiel​: what makes you say that?
<masak> vendethiel​: see lizmat++'s first eval.
<vendethiel> seeing the commit that added it to rakudo :-)
<vendethiel> and telling TimToady​: NOT TO MAKE IT STATE :P
<masak> huh.
<masak> why not?
<lizmat> m​: sub a { $++ }; say a for ^5
<camelia> rakudo-moar 315ec6​: OUTPUT«0␤1␤2␤3␤4␤»
<masak> seems it is in some cases...
<vendethiel> masak​: ETOOMUCHMAGIC.
<vendethiel> ETOOIMPLICIT
<lizmat> fwiw, I'm fine with state, as my wouldn't make much sense
<masak> I'm fine with state, too.
<masak> I can see where vendethiel is coming from, but I don't mind much.
<vendethiel> newcomers will mind...
<masak> if I can write `$++` instead of `(state $)++` 500 times before
I die, that will be worth it :)
<vendethiel> ++state is cool too :p
<vendethiel> or er, state++
<masak> m​: sub foo { ++$ }; say foo for ^5
<camelia> rakudo-moar 315ec6​: OUTPUT«1␤2␤3␤4␤5␤»
<vendethiel> m​: sub a { state++ }; say a for ^5
<camelia> rakudo-moar 315ec6​: OUTPUT«===SORRY!=== Error while
compiling /tmp/7a8JxXYEd3␤Malformed state [...]
<vendethiel> m​: sub a { (state)++ }; say a for ^5
<camelia> rakudo-moar 315ec6​: OUTPUT«===SORRY!=== Error while
compiling /tmp/8nHJRjW3si␤Malformed state [...]
<vendethiel> meh.
<masak> declarators don't work that way.
<masak> they want a declaratee.
<vendethiel> and when do they want it
<masak> vendethiel​: I mean, I can't think of a single case where you
write a declarator (`my`, `our`, `state`, `has`, etc) and then nothing
afterwards. it feels "wrong", parsing-wise.
<vendethiel> well, semantics-wise for me
<lizmat> m​: sub a { (state $ = "A")++ }; say a for ^5
<camelia> rakudo-moar 315ec6​: OUTPUT«A␤B␤C␤D␤E␤»
<lizmat> m​: sub a { ($ = "A")++ }; say a for ^5 # should just be the same
<camelia> rakudo-moar 315ec6​: OUTPUT«A␤A␤A␤A␤A␤»

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Oct 26, 2014

From @masak

<TimToady> as for $ = 'A', currently that's equivalent to (state $) = 'A', since the $ doesn't actually parse as a declarator, but is promoted to a declaration in the actions
<TimToady> maybe we can fix that somehow
<TimToady> could also argue that it should be restricted to integers
* TimToady loves to argue so much that he often ends up arguing both sides. :)
* TimToady would've made a bad lawyer... :)

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Dec 1, 2017

From @AlexDaniel

Still reproducible (2017.11, HEAD(5929887))

On 2014-10-26 08​:58​:08, masak wrote​:

<TimToady> as for $ = 'A', currently that's equivalent to (state $) =
'A', since the $ doesn't actually parse as a declarator, but is
promoted to a declaration in the actions
<TimToady> maybe we can fix that somehow
<TimToady> could also argue that it should be restricted to integers
* TimToady loves to argue so much that he often ends up arguing both
sides. :)
* TimToady would've made a bad lawyer... :)

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Dec 1, 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
Projects
None yet
1 participant
You can’t perform that action at this time.