Patrick R. Michaud a écrit :
I've put together a draft with my ideas and design for (re-)implementing lexicals in Parrot -- now available at
http://www.pmichaud.com/perl6/lexical.txt .

It's a first draft and might be a bit confusing in places,
but overall I think it's a far cleaner design than the
current implementation but also handles the vast bulk of
what we need (or can be made to do so easily).

Anyway, comments greatly appreciated.


Currently, the bigger issue in Lua on Parrot is lexical or upvalue in Lua jargon (the reason for Lua on Parrot is not really Lua). The following Lua code doesn't give the expected result (from languages/lua/t/closure.t) :
    a = {}
    local x = 20
    for i=1,10 do
        local y = 0
        a[i] = function () y=y+1; return x+y end
    end

    print(a[1]())
    print(a[1]())
    print(a[2]())

    --[[
    The loop creates ten closures (that is, ten instances of
    the anonymous function). Each of these closures uses
    a different y variable, while all of them share the same x.
    ]]


With the current Parrot, I never found a way to do it.

So, I'll be happy if this revisiting handles this issue.

François.

Pm






Reply via email to