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? I'm frankly getting a little tired of having someone new enter the conversation every few hours and say "Let's try this discussion," after which I have to expend energy on several emails back and forth to get the broad, complex example offered narrowed down to the salient points, over and over again -- especially since the salient points are the same in each case. One step forward, three steps back. > > >From the Wikipedia definition: > > [A] closure is a function that refers to free variables in its > lexical context. Also from the Wikipedia definition: [A] closure is a function 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. > > Even if the Ruby block itself contains no reference to free variables, > the stored lexical context associated with the block does so > implicitly. In the case of: > > array.each do > puts "each!" > end > > the block may be get executed immediately w/o referencing free > variables, but the ruby implementation has no way of knowing that. > Thus, every block carries around a lexical context which references > all free variables in that context. Thus, every block is a closure. 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. -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] "A script is what you give the actors. A program is what you give the audience." - Larry Wall