From: Chad Perrin Date: 2006-08-01T11:28:23+09:00 Subject: Re: I thought this was the one that worked? On Tue, Aug 01, 2006 at 10:15:09AM +0900, Just Another Victim of the Ambient Morality wrote: > > "Chad Perrin" wrote in message > news:20060731230559.GA27910@apotheon.com... > > > > Who said it's different? I'm just asking about the foregoing statement > > that all blocks are closures (which strikes me as improbable). That's > > like saying that this will generate a closure (which it won't): > > > > sub foo { > > return sub { my $bar = 1; print ++$bar }; > > } > > Okay, the mere fact that you "used a Perl example" demonstrates that > there is a miscommunication going on here. Why would an example from Perl > clear anything up? It's a different language with different semantics. Are > you hoping that we all know Perl? I'm hoping that demonstrating how it does or does not work in Perl will make it clear what I'm talking about, based on similar syntax between the languages, so that I can find out what does and does not work in Ruby. Duh? > > I suspect what's happening here is that we're mixing up code blocks with > "Ruby blocks." > These are examples of what most programmers would call blocks but are > _not_ Ruby blocks: I know there's a difference, thanks. The problem is that nobody seems to be addressing the fact that for a proper closure, as I understand it, the closure variable has to go out of scope while the block of code does not. If Ruby blocks do something automagical to make variables declared within them go out of scope while the block is still in scope, I'd like to know. If there's some other way to "close" the block's data while the block is still available, I'd like to know that, too. > > def some_method_as_function > # code block goes here but > # in the Ruby world, this is not a "block..." > end > > while some_condition > # code block goes here but > # in the Ruby world, this is not a "block..." > end > > > These are Ruby blocks: > > > [1, 2, 3].each do |i| > # this is a Ruby block and > # this is a closure > end So explain how it is a closure. Please. > > some_local_variable = 2 > func = lambda { puts some_local_variable } # a one line block and closure Am I to assume that some_local_variable is going out of scope outside of the lambda declaration at some point, to create that closure? > > All things that are called "blocks" in Ruby are closures. > Do you still have any questions on the matter? Yes. Are you just failing to explain how these things are closures, or do you not know what a closure is? You keep telling me blocks are closures somehow, but you're not explaining how. Saying it doesn't make it so. Please explain what I'm missing. -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] This sig for rent: a Signify v1.14 production from http://www.debian.org/