[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: partial evaluation
- From: Peter Wang <tjaden@...>
- Date: Thu, 2 Nov 2000 15:11:16 +1100
paul@theV.net <paul@theV.net> wrote:
> I have the following code:
>
...
>
> But Lua says
>
> error: cannot access a variable in outer scope;
> last token read: `f' at line 7 in file `a.lua'
You need to use "upvalues" (see the manual), e.g.
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))
--
CINEMUCK (SI ne muk), n. The combination of popcorn, soda, and melted
chocolate which covers the floors of movie theaters.
-- Rich Hall, "Sniglets"