Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^8: How will you use state declared variables in Perl6?

by BrowserUk (Patriarch)
on Jul 08, 2005 at 23:23 UTC ( [id://473609]=note: print w/replies, xml ) Need Help??


in reply to Re^7: How will you use state declared variables in Perl6?
in thread How will you use state declared variables in Perl6?

Why should it have to "segregate", unless you have a busted inheritance hierarchy that doesn't actually represent ISA relationships?

I was trying to think of a use for state. The potential use I thought of was counting instances of a class--Probably better served by a Class variable anyway--but it could be used that way until inheritance is involved at which point it gets iffy whether instances of the subclass are instances of the class. But forget that as there are better ways of doing it.

That leaves the question, what is a good use for state vars, which is probably the question Limbic~Region was asking in the first place.

My summation of the information you provided in this thread is that state vars are basically the same as closures, except that you can declare their scope from within the scope they are to be closed over, rather than having to declare them outside that scope in order for the sub(method/submethod) to close over them.

Is that a reasonable definition?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Replies are listed 'Best First'.
Re^9: How will you use state declared variables in Perl6?
by TimToady (Parson) on Jul 08, 2005 at 23:34 UTC
    It'll do. I probably wouldn't call them closures, but say rather that they participate in a closure, insofar as a particular closure might capture multiple variables simultaneously. And I wouldn't define them that way to someone who isn't ready to understand closures. "Persistent lexicals" works better for that bunch. But either view is a lot better than thinking of them as globals.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://473609]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-03-19 03:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found