On Mon, Feb 17, 2014 at 1:02 PM, Jameson Nash <[email protected]> wrote:

> Fil, your second form of writing the function is functionally
> identical to the first -- it is only a difference in syntax and makes
> absolutely no difference to the compiler. You are simply rehashing the
> old question of why julia can't optimize when using global variables.
>

Thanks for this, so an inline function is still an anonymous function. I
thought there was some more fundamental differences between the 'function'
and '->' syntax.


> In your first example, fn is const, but f is not. This means that f
> could change while executing the comprehension (and the output type of
> f), but fn cannot.


Right, did not appreciate the const difference. But would you expect this
to resolve it?

julia> const f = i->i
(anonymous function)

julia> [f(x) for x in [1,2,3]]
3-element Array{Any,1}:
 1
 2
 3

Also in case f isn't const enough, a local:
julia> function g()
       local f = i->i
       [f(x) for x in [1,2,3]]
       end
g (generic function with 1 method)

julia> g()
3-element Array{Any,1}:
 1
 2
 3

Reply via email to