in reply to Re^5: Experimental features: autoderef vs postfix deref
in thread Experimental features: autoderef vs postfix deref

First up, no offence taken at all.

It would appear I'm missing something, but I don't know what it is.

I followed your link to state (in the node I responded to and again here). That's just a Super Search for the keyword 'state'. Nothing immediately useful there as far as I can see; I initially just shrugged it off as a typo, assuming you'd meant it to point to the state doco, i.e. http://perldoc.perl.org/functions/state.html. So, perhaps your link should point elsewhere - and that's the bit I'm missing.

The only other thing I can think of is that you did want $closure in

sub x1 { state $closure ... } sub x2 { state $closure ... }

to reference to same variable. Or, at least, different syntax (or something) to achieve that sort of result.

— Ken

Replies are listed 'Best First'.
Re^7: Experimental features: autoderef vs postfix deref
by BrowserUk (Patriarch) on Jul 12, 2015 at 23:13 UTC
    The only other thing I can think of is that you did want $closure in ... to reference to same variable.

    Exactly.

    With this syntax:

    { my $closure; sub x1{ ... } sub x2{ ... } sub x3{ ... } ... }

    I can share the closure between as many subroutines as I need.

    With embedded state, the closure's scope is restricted to the one subroutine.

    I could do:

    { state $closure; sub x1{ ... } sub x2{ ... } sub x3{ ... } ... }

    But then state has no advantage over the simple closure.

    I did start to use state when it first appeared (there are probably several examples here somewhere), but after the third or fourth time of having to revert it back to a standard closure as needs changed, I simply stopped using it.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
    I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

      OK, I fully understand what you're driving at now. Thanks for the explanation.

      — Ken