[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: functional programming-like closures
- From: paul@...
- Date: Mon, 10 Sep 2001 19:53:47 +0800
In case you really miss this, here is how we do it in our game:
--
-- it joins array t2 to the end of array t1. t1 is altered.
--
function join_array(t1, t2)
for k, v in t2 do
tinsert(t1, v)
end
end
--
-- make a new function by delaying the call to the real one with ready
-- arguments.
--
function mk_func(func, ...)
local args = arg
return function(...)
join_array(%args, arg)
call(%func, %args)
end
end
--
-- So, when you have f(x, y, z), and you can do
--
g = mk_func(f, x)
--
-- and later invoked g like this
--
g(y, z)
Regards,
.paul.
On Mon, Sep 10, 2001 at 07:01:21AM -0400, John D. Ramsdell wrote:
> RLake@oxfam.org.uk writes:
>
> > I actually quite liked the fact that Lua does functional (in the
> > functional programming sense) closures. I'll miss it -- but I guess
> > I'm in the minority.
>
> The current version of Lua does not provide "functional (in the
> functional programming sense) closures". The upvalue-less version
> coming will provide the kind of closures that are provided by modern
> functional programming languages, such as Scheme, and ML. The whole
> point of dumping upvalues is to get real closures! I promise you that
> once you gain experience with the real thing, you won't miss upvalues.
>
> To the Core Lua Team: Congradulations on giving variables in Lua
> static nested scope.
>
> To Christian Vogler: Thank you so much for providing lua-mode.el!!!
>
> John