On Tue, Aug 01, 2006 at 09:57:03AM +0900, Logan Capaldo wrote:
> On Jul 31, 2006, at 7:07 PM, Chad Perrin wrote:
> 
> >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 };
> >}
> >
> 
> In ruby it does. I'm having difficulty thinking of a simple example  
> to demonstrate it, but basically it grabs the whole environment  
> whether theres a reference to a variable or not. It does this to  
> allow things like:
> 
> def foo
>   x = 1
>   lambda { puts eval("X".downcase) }
> end
> 
> You might say, so it just notices that you're using eval. But  
> consider this:
> 
> def bar
>   x = 1
>   lambda { puts send("lave".reverse, "y".sub(/y/, 'x')) }
> end
> 
> Obviously contrived examples, but this is part of the reason blocks  
> "leak" memory.

Um, no . . . that's not the equivalent of what I just posted.  To make
it equivalent, you'd have to do something like this:

def foo
  lambda { x = 1; puts eval("X".downcase) }
end

-- 
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
print substr("Just another Perl hacker", 0, -2);