in reply to Nailing down closures!

Closures are sometimes called "inside out objects." Thinking about them that way helped me understand closures.

Explanation: Objects are data associated with subroutines. Inside-out Objects (or closures) are subroutines associated with data.

See Achieving Closure.

Replies are listed 'Best First'.
Re^2: Nailing down closures!
by revdiablo (Prior) on Dec 05, 2005 at 16:14 UTC
    Closures are sometimes called "inside out objects."

    Hmm, interesting. I've always associated the term "inside out objects" specifically with the technique of using closures as the implementation of an object's storage, instead of storing data directly in the object (as described ably in Re: Tutorial: Introduction to Object-Oriented Programming).

    But your usage of the term certainly makes sense, and seems more generally applicable. Now I wonder which one came first? I have a feeling it's the more general definition, but I'm curious if anybody out there knows for sure?

Re^2: Nailing down closures!
by Perl Mouse (Chaplain) on Dec 05, 2005 at 16:37 UTC
    Closues are sometimes called "inside out objects."
    By whom? I know 'inside out objects' as a technique to store object attributes in lexical, class-wide, hashes - one hash per attribute.

    No closures involved.

    Perl --((8:>*
      Simon Cozens... see the article I linked to above.

      Since this terminology seems to be at least slightly controversial, and I'm not 100% sure about my understanding, and this whole thread is about "nailing down" perhaps you could link to something beginner-oriented that espouses your views of inside-outs?

      No closures involved.

      Why do you need object attributes then if you never use them?

      Going by the code you have posted elsewhere your InsideOut attribute handlers are actually closures. At least iirc, you use lexical hashes to store the attribute values and these hashes are declared outside of the subs that reference them, therefore those subs are closures. (Dump one of them with DDS and see what happens).

      ---
      $world=~s/war/peace/g

      By whom? I know 'inside out objects' as a technique to store object attributes in lexical, class-wide, hashes - one hash per attribute.

      See this post for one example.

      I don't think it's original to Barrie though. It's a analogy I've come across several times outside the Perl world in either direction (closures are inside out objects, objects are inside out closures) depending on who knows what.

      Not that I think it's a particularly good analogy mind...