From: Jacob Fugal Date: 2006-08-01T07:54:33+09:00 Subject: Re: I thought this was the one that worked? On 7/31/06, Chad Perrin wrote: > On Tue, Aug 01, 2006 at 07:05:31AM +0900, Logan Capaldo wrote: > > I'm not sure I understand your question. All blocks (by blocks I mean > > do / end and { } ) are (lexically scoped) closures. > > I'll use a Perl example: > > sub foo { > my $bar = 1; > return sub { print ++$bar }; > } > > my $baz = foo(); > > Voila. $baz contains a lexical closure. This is the case because the > return value from foo() was lexically "closed" by virtue of $bar going > out of scope, but its value still being accessible via the coderef > returned from foo() and assigned to $baz. How is this different from: def foo bar = 1 return proc{ bar += 1; puts bar } end begin puts bar rescue Exception => e puts e end # => undefined local variable or method `bar' for main:Object baz = foo baz.call # => 2 baz.call # => 3 baz.call # => 4 ... Jacob Fugal