Closure & local_variables


#1

Hello,

given:

l=lambda{p local_variables;p a}
a=:whatever
l[]

I know that ‘a’ variable shoud not be visible for closure, but why
local_variables reports that it exists ? Is this behaviour intended ?

lopex


#2

On Mar 3, 2006, at 4:48 PM, Marcin MielżyÅ?ski wrote:

lopex

l is closing over main, main has a local_variables method, that is
what is being called not the proc’s local_variables.


#3

Marcin MielżyÅ?ski wrote:

Hello,

given:

l=lambda{p local_variables;p a}
a=:whatever
l[]

I know that ‘a’ variable shoud not be visible for closure, but why
local_variables reports that it exists ? Is this behaviour intended ?

Well, #local_variables is a method call so it resolves
at call time (at which point a is included). You could
also #eval ‘a’ at that point :slight_smile:

lopex

E