[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: More schematic lua (Was: Re: There's gotta be a more "Lua" wayto do this)
- From: RLake@...
- Date: Thu, 3 Jul 2003 16:47:47 -0500
Sorry, I couldn't resist. The generalised curry function
(memoise was in some other post) showing an interesting
example of on-the-fly compilation:
do
local function currifier(n)
local i = 0
local a = string.gsub("a#" .. string.rep(", a#", n - 1),
"#",
function() i = i + 1; return i end)
return loadstring ([[
return function(fn, ]] ..a.. [[)
return function(...)
return fn(]] ..a.. [[, unpack(arg))
end
end
]])()
end
local curries = memoise(currifier)
curries[0] = function(fn) return fn end
function curry(fn, ...)
return curries[arg.n](fn, unpack(arg))
end
end