develooper Front page | perl.perl5.porters | Postings from April 2007

Re: Differences between state variables and smart matches in 5.10 and 6

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
April 2, 2007 02:39
Subject:
Re: Differences between state variables and smart matches in 5.10 and 6
Message ID:
b77c1dce0704020239v9fc3d4xc8feb76eae1f177c@mail.gmail.com
On 02/04/07, Gerard Goossen <gerard@tty.nl> wrote:
> I find the whole 'state $x' effecting the rhs is very tricky.
> And having this magic in sassign seems wrong. It means that
> '(state $x) = "foo"' assigns "foo" to $x every time.

That's by design. Or else, what should (state $x, my $y) = f() do ?

> And also 'state $x ||= "foo"' works every time.
> If the magic remains I think it should be done by
> 'state $x' returning an LVALUE with "get" and "set" magic.
> But I think it is much simpler that 'state $x' always returns the
> state variable $x, that is just a declaration.

That would be much simpler, yes. Less surprising, too. I might back
out all changes to sassign before 5.10. Still wondering.

> If you want to initialize it only once you can do 'state $x //= "foo"'
> It is immediatly clear that $x will keeps it old value, and "foo" is
> only evaluated if $x is uninitialized.

But that's a different semantics, since you can then undef $x and have
the assignment occur again.

What we would like to have here is ONCE blocks, actually. But I don't
see how to do this without a modifiable optree (even with
indirections).

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About