On Tue Oct 16 17:31:22 2012, aristotle wrote: > * Father Chrysostomos via RT <perlbug-comment@perl.org> [2012-10-16 23:50]: > > So that means state(our @foo) = ... should assign to the package > > variable @foo once. > > > > Right? > > $ perl -E'my (our $foo) = 1; say $::foo ? 1 : 0' > 1 > $ perl -E'our (my $foo) = 1; say $::foo ? 1 : 0' > 0 > > To my mind that is a “no”. So far `state` is basically just another > declarator, which in Perl can be strewn throughout an expression, and > the closest declarator wins. But it’s already not quite just another > declarator, but one with some special behaviour. That’s fine but I don’t > think I want its semantics complicated further so that it becomes kind > of a declarator with some special behaviour that also modifies some > other declarators within the expression. > > (Maybe it is a missed opportunity that isn’t spelled `state my`. But then would return \state my $x give the same variable each time? (I.e., I don’t consider it a lost opportunity, as state is yet another scope, different from my and our.) > I care > not to tug that ship back into the port now by the anchor line though.) > > For those times where you really need this functionality you might be > able to just abuse lexical `state`: > > { state $init = do { our $foo = 1 } } > > Not as obvious as I would like, but at least not ugly either. My question is more ‘Where do we draw the line?’ than ‘Isn’t this useful?’ Where do *you* think we should draw the line between state controlling the rhs of assignment and state not controlling the rhs of assignment? And will it involve more than one special case? What I like about my explanation above between the difference between (state @a) and state(@a) is that it can be said simply with no qualifications: = is special if the left-hand operand is state(...). -- Father ChrysostomosThread Previous | Thread Next