Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Priority in chained comparisons in Julia, does "var1 && var2 != 1" mean "(var1 and var2) != 1"?

I have a questions regarding the chained comparisons in Julia. I read this section in the manual but it is still unclear.

In Julia, does this:

if var1 && var2 != 1

mean this (in Python):

if (var1 and var2) != 1:

Thank you!

like image 473
Saullo G. P. Castro Avatar asked Aug 22 '13 13:08

Saullo G. P. Castro


1 Answers

You can always quote an expression to see how the parser interprets it:

julia> :(var1 && var2 != 1)
:(var1 && (var2!=1))

In this case, the != binds more tightly than the &&. This is standard precedence in languages that have these two operators) such as C and Java.

like image 148
StefanKarpinski Avatar answered Jan 01 '23 12:01

StefanKarpinski