I can not understand why Julia displays such results in chain comparisons?

Hello dear friends
I can not understand why Julia displays the following result for the expression of chain comparisons:

``````julia> v(x) = (println(x); x)
v (generic function with 1 method)

julia> v(1) < v(3) <= v(4) < v(5) < v(10)
3
1
4
5
10
true
``````

Why Julia does not show the following result:

``````julia> v(1) < v(3) <= v(4) < v(5) < v(10)
1
3
4
5
10
true
``````

Hopefully I mean well. Tell me to explain more if Iβm saying bad question.
tnx:slightly_smiling_face:

1 Like

This might make it a bit more clear how things are executed

``````julia> f() = v(1) < v(3) <= v(4) < v(5) < v(10);

julia> @code_lowered f()
CodeInfo(
1 β %1  = (Main.v)(3)
β   %2  = (Main.v)(1)
β   %3  = %2 < %1
βββ       goto #7 if not %3
2 β %5  = (Main.v)(4)
β   %6  = %1 <= %5
βββ       goto #6 if not %6
3 β %8  = (Main.v)(5)
β   %9  = %5 < %8
βββ       goto #5 if not %9
4 β %11 = (Main.v)(10)
β   %12 = %8 < %11
βββ       return %12
5 β       return false
6 β       return false
7 β       return false
)
``````
1 Like

yes i did, but i canβt understand.

The compiler is free to rearrange the order to produce more efficient code, or for any other reason. As it says in the manual, the order is undefined, and you should not depend on it.

I am very beginner and I do not understand anything from the code you wrote.

Yes, I read that. But finally, the one who made Julia must know whatβs going on. Is not it?