Julia quirks (v. 1.9.0 and higher)

I’m a huge fan of Julia compiler, even if my knowledge of it is very limited. As you should expected with such complicated program it has few quirks that we should be aware of. Since I’m not advanced Julia programmer, I will just post here what I found in Julia 1.9.3 and ask you for more examples of quirky behaviour.

In one tutorial they said that this code is illegal (it would be in C-derived languages and many others):
x + y = 2
It compiles and gives you generic function with 1 method. Now we have
julia> 1 + 3
2

2 Likes

This is the largest collection of quirks I’m familiar with

2 Likes

Although:

2 Likes

+ is just a normal function in Julia. When you write + you typically execute the Base.:+ function (which is implicitly imported into modules) but (as with any other function) you can shadow outer functions:

julia> a + b = 1
+ (generic function with 1 method)

julia> 1+2
1

Now, you can not shadow a function if you have already used it and resolved to some other function:

julia> 1+2
3

julia> a + b = 1
ERROR: invalid method definition in Main: function Base.+ must be explicitly imported to be extended

And even if you define a + b = 1 as in the first example, that doesn’t mean that all of Julia’s math is suddenly wrong. All the other places using + still resolves to Base.:+ which is unchanged:

julia> a + b = 1
+ (generic function with 1 method)

julia> 1 + 2
1

julia> Base.:+(1, 2)
3
6 Likes