On Wed, Feb 06, 2008 at 03:33:14PM +0100, Klaas-Jan Stol wrote:
> function foo()
> 
>     local a = 2
> 
>     function bar()
>         print(a)
>     end
> end
> 
> foo()
> bar()
> 
> What happens here is, a function foo is defined, in which a  local var. "a"
> is initialized to the value "2". Another function is defined, called "bar",
> which prints the value of variable a. As "bar" is lexically nested within
> function foo, "bar" has access to "a". Note that "bar" is only defined, it's
> not run when "foo" is active. (function foo() ... can be rewritten as "foo =
> function()..." )
> 
> Now, after defining "foo", foo is invoked: foo(). This will actually create
> the lexical "a", and define "bar". After running foo, there should be a
> function "bar".
> So now we can invoke "bar": bar(). When running bar, the value of the
> lexical "a" should be printed.
> 
> This doesn't work. It seems to me that the generated PIR is correct. I'm not
> clear why this doesn't work.
> Anybody who sees an obvious error I made?

It has to do with Parrot's handling of closures.  The problem is
that 'bar' isn't being stored as a Closure PMC.  Somewhere in the
generated PIR we need to have a 'newclosure' operation on the
code representing the "bar" function to create a Closure PMC and
store that in 'bar'.

This is likely related to the earlier message in the thread about
overall handling of closures in PCT, for which I'll get a more detailed
response out shortly.

Pm

Reply via email to