Actually, I'm not sure about the slowness. :) julia> g = @curry 100 + (anonymous function)
julia> @time foldr(|>, g, [1:100]) elapsed time: 0.468942365 seconds (594640 bytes allocated) # A lot of this is for compiling g 5050 julia> @time foldr(|>, g, [1:100]) elapsed time: 0.000155383 seconds (71712 bytes allocated) 5050 julia> @time +([1:100]...) elapsed time: 0.000209564 seconds (26792 bytes allocated) 5050 On Tue, Sep 2, 2014 at 4:14 AM, Shashi Gowda <shashigowd...@gmail.com> wrote: > Here's a macro for currying. Since there are vararg functions we will need > to specify the number of arguments to curry away at. > > macro curry(n, f) > syms = [gensym() for i=1:n] > foldl((ex, sym) -> Expr(:->, sym, ex), Expr(:call, f, syms...), > reverse(syms)) > end > > add4 = @curry 4 + > > add4(1)(2)(3)(4) > #=> 10 > foldr(|>, add4, [1:4]) > #=> 10 > > This is really really slow though. > > > On Tue, Sep 2, 2014 at 2:50 AM, Michael Louwrens < > michael.w.louwr...@outlook.com> wrote: > >> I just wanted to add an example of function currying in Julia. >> >> It isn't exactly pretty but it does work! I don't expect it to be >> performant however. >> >> julia> >> function Add(x) >> return function f(y) >> return x + y >> end >> end >> >> >> Add (generic function with 1 method) >> >> julia> Add(1)(2) >> 3 >> >> A simple example, but it does show basic currying working fine. >> > >