Skip Menu |
Report information
Id: 123060
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: masak <cmasak [at] gmail.com>
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: [BUG] `$++` statements in routines sometimes give the anonymous variable `my` scoping, sometimes `state` scoping in Rakudo
To: rakudobug [...] perl.org
From: Carl Mäsak <cmasak [...] gmail.com>
Date: Sun, 26 Oct 2014 15:46:03 +0100
Download (untitled) / with headers
text/plain 2.9k
<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: https://github.com/rakudo/rakudo/commit/ce263122bc0ae6e2fee51c166c06abd9d00ba771 <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␤»
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 409b
<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... :)
Still reproducible (2017.11, HEAD(5929887))

On 2014-10-26 08:58:08, masak wrote:
Show quoted text
> <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... :)




This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org