On Mon, Apr 02, 2007 at 11:39:35AM +0200, Rafael Garcia-Suarez wrote: > 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. I would like that. > >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). Of course, I just ment that using 'state $x //= "foo"' will probably do what you want, it isn't exactly a ONCE block, but if you don't undef $x it will behave like one. Gerard GoossenThread Previous | Thread Next