On Sunday, January 12, 2014 6:02:30 PM UTC-6, Andrew Burrows wrote:
>
> Hi
>
> I'm rather new to Julia, but I've come across some rather puzzling 
> behaviour of the language.
>
> The following code works fine and the assert passes:
>
> a(x) = 12345
> b(x) = a(x)
> a(x::Int64) = 1000
> @assert b(1)== 1000
>
> But this near identical code does not, throwing an assertion error:
>
> a(x) = 12345
> b(x) = a(x)
> b(1) # <----------- This line is new
> a(x::Int64) = 1000
> @assert b(1)== 1000
>
> ... 

> Is this behaviour a bug or is it by design? Am I doing something wrong or 
> is there something I can do to disable what ever is caching my method 
> definition or is there any way to work around it?
>
 
The "method cache" you refer to is in fact the JIT compiled code. In the 
first instance, a() and b() are unused until the assertion; the new 
definition is already in place and everything is cool. In the second 
instance, calling b(1) compiles a(), and since a() is small, inlines it 
into b(). As John mentioned earlier, Julia currently doesn't know that, so 
that adding the new definition of a() does not cause recompilation of b().

Reply via email to