RE: The Curry Challenge
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: RE: The Curry Challenge
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: 2007年1月11日 18:39:24 -0500
I made 2 versions, one similar to yours, no arrays but recursive, and
one using arrays that is not recursive (I don't use argument list length
explictly, but through ipairs). Not very interesting, but they are
short.
-- Recursive without arrays
function curry(f, onearg, ...)
if not onearg then
return f
end
return curry(function(...) return f(onearg, ...) end, ...)
end
-- Non-recursive with arrays
function curry(f, ...)
local cargs = {...}
return function(...)
local args = {}
for _,v in ipairs(cargs) do args[#args+1] = v end
for _,v in ipairs({...}) do args[#args+1] = v end
return f(unpack(args))
end
end