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 <
[email protected]> 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.
>