lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I have the following code:

---------
add = function (x, y)
        return x + y
    end             

partial = function (f, i)
        local c = function (j)   
                        return f(i, j)  
                  end                  
        return c
    end         

add_one = partial(add, 1)

print (add_one(2))
---------

But Lua says

error: cannot access a variable in outer scope;
  last token read: `f' at line 7 in file `a.lua'

It is no surprise that Lua does not suport partial function
evaluation, but is there any chance to get around with this
variable scope problem?

I've always find anonymous function very powerful if you
can compose function with function freely, as commonly seen
in functional languages.

Regards,
.paul.