lua-users home
lua-l archive

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


> -- curry: Partially apply a function
> --   f: function to apply partially
> --   a1 ... an: arguments to fix
> -- returns
> --   g: function with ai fixed
> function curry (f, ...)
>   local fix = arg
>   return function (...)
>            return f(
>              table.merge(unpack (fix), unpack (arg)))
>          end
> end

Shouldn't be
return f(unpack(table.merge(fix, arg))?

> Another useful functional is
> 
> -- compose: Compose some functions
> --   f1 ... fn: functions to compose
> -- returns
> --   g: composition of f1 ... fn
> --     args: arguments
> --   returns
> --     f1 (...fn (args)...)
> function compose (...)
>   local fns, n = arg, table.getn (arg)
>     return function (...)
>              for i = n, 1, -1 do
>                arg = pack (fns[i](unpack (arg)))
>              end
>              return unpack (arg)
>            end
>   end
> end
> 
> which is like currying, but one level up: it wraps up f
unction
> application rather than argument application. In lazy l
anguages you don't
> need compose.
> 
> ADVERT: All the code above is from my stdlib project, i
n CVS on
> lua-
users.org. I'm currently making over the code for Lua 5 (
it's all
> working in Lua 5, and I'm now "restyling" it a bit, mos
tly renaming the
> functions into tables, but also more subtle Lua 5-
ification). Unlike the
> Wiki, CVS is still working fine for reading *and* writi
ng. See
> http://cvs.sourceforge.net/viewcvs.py/lua-
users/stdlib/modules/
> 
> -- 
> http://www.mupsych.org/~rrt/ | taciturn, n.  a silent p
ot
> 



 
__________________________________________________________________________
Acabe com aquelas janelinhas que pulam na sua tela.
AntiPop-up UOL - É grátis!
http://antipopup.uol.com.br/