lua-users home
lua-l archive

Re: The Curry Challenge

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


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

AltStyle によって変換されたページ (->オリジナル) /