Hi All,

 This (2012) discussion <https://gist.github.com/dmbates/3939427> seems to 
suggest that generic functions cannot be used within closures in Julia.
But this seems to work now

function creator(y)

 function power(x) return x .^ y end

 function myNorm(x) return sum( power(x) ) end

 return power, myNorm

end

julia> (a, b) = creator(2.)
(power,myNorm)

julia> a(2)
4.0

julia> b([1. 2.])
5.0

I use generic functions because they support keyword optional arguments and 
I want to do things
such as 

function a(y, extra...) function b(x, extra...; z = true) "something" end 
end

which seems to work in terms of not "mixing up" the ... with the optional 
arguments.

Notice that I am mainly an R user, currently experimenting with Julia, so 
my approach might be completely wrong.
 
  [1]: https://gist.github.com/dmbates/3939427

Reply via email to