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.
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.

On Sun, Feb 16, 2014 at 8:48 PM, Fil Mackay <[email protected]> wrote:
> My workaround will be to avoid anonymous functions for the time being, and
> use this syntax instead of anonymous -> :
>
> [(function(x) x; end)(x) for x in [1,2,3]]
>
>
> On Mon, Feb 17, 2014 at 12:46 PM, Fil Mackay <[email protected]>
> wrote:
>>
>> On Mon, Feb 17, 2014 at 12:37 PM, Patrick O'Leary
>> <[email protected]> wrote:
>>>
>>> This is something more subtle than that:
>>>
>>> In [3]:
>>>
>>> [(x->x)(x) for x in [1,2,3]]
>>>
>>> Out[3]:
>>>
>>> 3-element Array{Int64,1}:
>>>  1
>>>  2
>>>  3
>>
>> Hmm. weird. Why does the type go through correctly when the anonymous
>> function is inline.
>>
>> Figured out why map() is not implemented as [(fx) for x in a] !! :)
>>
>>
>

Reply via email to