## Partial Application for Functions in Julia

Julia is purportedly a multi-paradigm language but I find their support for functional paradigms to be lacking. One feature that I looked for was Currying or Partial Application which corresponds to converting a function of multiple arguments into a sequence of single argument functions and taking a multiple argument function and fixing some of the arguments to produce a new function of lesser arity respectively. In Clojure one has the partial function for the latter. Here is my attempt to emulate this behaviour in Julia.

## Partial Application

function partial(f,a...)
( (b...) -> f(a...,b...) )
end


The function returns a lambda where the a… parameters are fixed. If you don’t know what the ellipsis do, check the documentation for “splat”. One can check the behavour is as expected

julia> function testf(x,y,z)
2*x+y*y+x*y*z
end
testf (generic function with 1 method)
julia> testf(2,3,4)
37
julia> partial(testf,2)(3,4)
37
julia> partial(testf,2,3)(4)
37


Of course you could just use a lambda.

## Passing Julia Type to C Function as Struct

There seems to be hardly any examples to be found about calling C from Julia (perhaps because people feel no need to do so). Moreover the docs are, at least to me, quite cryptic. So if anyone wants to get started here is a minimal example.

## Julia Code:

type mystruct
n::Int32
end


## C Code:

struct mystruct{
int n;
};
void structure(struct mystruct * input);
void sructure(struct mystruct * input){
(*input).n=99;
}


Compilation:
gcc -fPIC -shared rosetta.c -o rosetta.so

Execution:
julia> test=mystruct(10) mystruct(10)

 julia> ccall((:structure, "rosetta.so"), Void, (Ref{mystruct},), test); 

julia> test mystruct(99)