lua-users home
lua-l archive

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


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