Chad Perrin <perrin / apotheon.com> writes: > On Wed, Aug 02, 2006 at 12:45:46AM +0900, Marshall T. Vandegrift wrote: >> >> I'm joining the party late, but try this example: > > Why? Why should we keep trying unnecessarily complex examples that > introduce a bunch of variables (in the statistical study sense of the > term) that are not strictly relevant to the point under consideration? In the hope that eventually an example might satisfy your all your criteria and demonstrate why Ruby blocks are closures. And at the point I posted no one had yet provided an example where the closure-creation was implicit in the block being a block. I thought your confusion might be in how lambda { puts bar+=1 } explicitly creates an anonymous function which explicitly encloses a particular variable (environment) while array.each { puts "bar!" } does so implicitly. > That's not very useful. The Wikipedia "description" (it's not a > dictionary, and as such doesn't strictly speaking aim to "define" the > terms contained within it) is, for purposes of this discussion, > nigh-uselessly broad and lacking in coherent detail. How's this one from the Free On-line Dictionary of Computing?: closure 1. <programming> In a reduction system, a closure is a data structure that holds an expression and an environment of variable bindings in which that expression is to be evaluated. The variables may be local or global. Closures are used to represent unevaluated expressions when implementing functional programming languages with lazy evaluation. In a real implementation, both expression and environment are represented by pointers. [1] > Only if you accept a description of a closure as a definition. As I > implied elsewhere, however, "has four limbs" may be an accurate > description of a human, but the fact "dog" fits that description doesn't > make it a human. Oh, I see the problem: metaphysically you're more of an essentialist and I'm more of a functionalist. Alas, this can only end in tears. ;-) Seriously though, does the FOLDOC definition satisfy you? Because if so, all the examples demonstrate that a Ruby block contains (1) an expression (the code in the block) and (2) an environment of variable bindings. Even if that environment is empty[2] when the block is created, the environment is /still there/, as the examples which populate the environment after the fact demonstrate. [1] http://foldoc.org/foldoc.cgi?query=closure [2] Except that it always contains self, etc etc etc. -- Marshall T. Vandegrift <mvandegrift / iss.net> ISS.Researcher | 404.236.3986w 518.859.4559m