Ok, but the closure (the first version) in the 2012 post was not working julia> typeof(Rrss) Nothing
while now it does typeof(gridfgen([1.; 3.], [.2; 4.])) Function or maybe I am missing something. On Friday, March 13, 2015 at 2:02:34 PM UTC, Stefan Karpinski wrote: > > Closures have always worked, they just have some performance issues still. > > On Fri, Mar 13, 2015 at 9:05 AM, Matteo Fasiolo <[email protected] > <javascript:>> wrote: > >> 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 >> > >
