Hi -- On Tue, 1 Aug 2006, Chad Perrin wrote: > On Tue, Aug 01, 2006 at 06:15:10PM +0900, Just Another Victim of the Ambient Morality wrote: >> >> Well, I think that meshes just fine with my take on it... >> To tell you the truth, I didn't expect you to ask me what my >> understanding of a closure is because I thought I had already demonstrated >> it with the code sample I gave. Of course, you're busy digesting that and I >> appreciate it. It means you're actually trying to understand me (rather >> than just arguing at me. Something that happens all too often...). >> If I may be so bold, I think that, perhaps, blocks don't look like >> closures to you because you don't realize that methods that take blocks, >> like "each," "inject," "collect," etc.. are methods (member functions, if >> you're a C++ guy) and not arbitrary language constructs, like "if," "while," >> "for," etc... > > I'm not exactly a C++ guy. I suppose I'm more of a Perl guy than > anything else, judging by my familiarity with languages and the > assumption of a lack of loathing (I'm as familiar with PHP as with Perl, > but I don't like it very much, for instance). I am familiar with many > of the idioms and much of the semantic and syntactic theory of a lot of > languages, even if I don't use them much, though. The dangers of doing > consulting and industry analysis for money. . . . > > >> >> Now that I think about it, this whole argument can be settled with one >> simple question. If you doubt that all blocks are closures then show us a >> counter-example. Show us a "block" that is not a closure and I will show >> you how it's not a block... > > Is this a closure? You tell me (and tell me how, if it is): > > array.each do || You don't need the || (and hopefully that will continue to be the case forever, though there have been some troubling allusions to the possbiility of having it mean something some day...). > puts "Hello world!" > end See my last couple of posts about blocks vs. Procs. To which I'll add: it's not *quite* possible, I think, to argue that a block isn't a closure, because it does have its own scope -- so it's not like arguing that, say, an if statement is a closure. David -- http://www.rubypowerandlight.com => Ruby/Rails training & consultancy ----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <----- http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log http://www.manning.com/black => book, Ruby for Rails http://www.rubycentral.org => Ruby Central, Inc.