Monday 7 March 2016

Julia: Function as an argument to other function


In Julia, you can pass a function as an argument to other function. Following snippet pass the function sum as an argument to the function process_data.

julia> function sum(a, b)
           a+b
       end
sum (generic function with 2 methods)

julia> function process_data(f, a, b)
           f(a, b)
       end
process_data (generic function with 1 method)

julia> process_data(sum, 10, 20)
30

julia> process_data(sum, 10, 2000)
2010



Previous                                                 Next                                                 Home

No comments:

Post a Comment