[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: The Curry Challenge
- From: PA <petite.abeille@...>
- Date: Thu, 11 Jan 2007 23:42:42 +0100
On Jan 11, 2007, at 22:01, Bret Victor wrote:
I'm curious whether it's possible to write a "curry"
that doesn't create all this indirection. (And doesn't test the length
of { ... } and use explicit code for different lengths!)
Uses the length of the arguments *and* creates tables... 8^)
function unpacks( ... )
local someValues = {}
for anIndex = 1, select( "#", ... ) do
for _, aValue in ipairs( select( anIndex, ... ) ) do
someValues[ #someValues + 1] = aValue
end
end
return unpack( someValues )
end
function curry( aFunction, ... )
local someArguments = { ... }
return function( ... )
return aFunction( unpacks( someArguments, { ... } ) )
end
end