On Tue, Aug 01, 2006 at 10:15:09AM +0900, Just Another Victim of the
Ambient M. wrote:
}
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.
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.