"Chad Perrin" <perrin / apotheon.com> wrote in message 
news:20060801190919.GB30216 / apotheon.com...
> On Tue, Aug 01, 2006 at 10:20:06PM +0900, Just Another Victim of the 
> Ambient Morality wrote:
>> "Chad Perrin" <perrin / apotheon.com> wrote in message
>> >
>> >  2. If a lambda has the ability to access its context, but there isn't
>> >  any context to access, is it still a closure?
>>
>>     How about this:
>>
>> 3. If a lambda has the ability to access its context and nothing's around 
>> to
>> use it, does it still make a closure?
>>
>>     I think 3 is a better characterization than 2.  Here's some code to
>> demonstrate:
>
> I don't.  A closure is a closure whether you use it or not, just as a
> remote control for the TV is a remote control for the TV whether you use
> it or not.  What's actually relevant to the discussion is more like the
> question of whether a remote control for the TV is still a remote
> control for the TV if it was built with no TV on which it could operate.

    I think 3 is a better example because in all the examples of (alleged) 
closures we've given each other, there usually was a TV... I mean, a 
context...


>> variable = 2  # this is the context
>>
>> [1, 2, 3].each do |i|
>>     # it sounds as if you think this is the "context"
>>     puts i + variable
>>
>>     # either way, we're using the context so
>>     # we agree that this is a closure
>> end
>
> Actually . . . no.  If that was a closure just because there was a
> variable nearby that it could access, then in any script that contains a
> lexical variable at the "base level" of the script, and in any script
> that has global variables, every scope enclosed within the scope of the
> script would be a closure.

    One step forward, two steps back...
    I thought I had demonstrated that blocks passed into the "each" method 
of class "Array" were closures?  Do you think the following two situations 
are the similar?


context = 2

if some_condition
    # this is not a Ruby block nor is it a closure...
    puts context
end

[1, 2, 3].each do |i|
    # this is a block and is also a closure
    puts context * i
end


    The two code blocks (not Ruby blocks) above look similar but are very 
different.
    The "if" keyword is a language construct and does not take a block.  I 
cannot change the behaviour of "if."
    In contrast, "each" is not a keyword and is not a language construct.  I 
may redefine (or define!) it and change its behaviour.  It is a simple 
method and, within it, created its own scope which is outside the closing 
scope of the closure (block) passed in...  We don't see that here but that's 
not relevant.  It happens nonetheless...


>> > I'm beginning to think the question of whether it's actually a closure
>> > really IS a question for a programming koan, after all.  If so, I'm 
>> > glad
>> > we've at least narrowed the discussion down to this point at last.
>>
>>     I agree that we have finally narrowed down the discussion.  This 
>> might
>> have happened sooner if I had actually followed the thread...
>
> Unfortunately, it was David and possibly one or two others who have been
> instrumental in narrowing it down.  You're still talking about things
> that don't seem to bear on what I was saying at all.

    Why is this unfortunate?
    I only assumed I had something to do with it because you came to the 
quoted conclusion while responding to my post.  This is usually 
reasonable...


>>     Not to be insulting but there's a part of me that thinks that you 
>> came
>> up with this distinction to hide the (embarrassing?) fact that you didn't
>> know that all blocks were closures...
>
> Not to be insulting, but I don't think you've grasped the fact that
> there's more to being a closure than being a language construct that
> someone once said was a closure.

    I've demonstrated how it was a closure in previous posts.  You said you 
were "digesting" it so I ceased to expand on it.  Have you digested them and 
decided they were not closures?