On Wed, 2 Aug 2006, Chad Perrin wrote:

>> closures in ruby have neither global nor lexical scope though:
>>
>>   harp:~ > cat a.rb
>>   class Object
>>     def closure(&b) b end
>>   end
>>
>>   c = closure
>>
>>   def a() p 42 end
>>   eval 'a', c
>>
>>   def a() p 'forty-two' end
>>   eval 'a', c
>>
>>   harp:~ > ruby a.rb
>>   42
>>   "forty-two"
>>
>>
>> the scoping is dynamic.  in otherwords we can add things to the enclosed
>> state
>> later - it's not frozen at the time the closure is created.
>>
>> that can refine the def a bit.
>
> That's not much of a closure, then.

that's an absurd thing to say don't you think?  it's not bad or good - it is
what it is.  it is in fact a very pure closure which perfectly captures the
state in which it was defined in.  note that i said it captures the 'state'
and not the 'state of the state' - in otherwords it has a pointer to the state
and not a copy of the state.  that way it even has access to newly added
information as my example shows.  this is amazingly powerful even if it
doesn't fit your idea of what a closure may or may not be.

i might add that perl has exactly this kind of enclosing semantics and is
considered to have 'true' closures.

-a
-- 
we can never obtain peace in the outer world until we make peace with
ourselves.
- h.h. the 14th dali lama