I am teaching some programming using Julia, and I faced a common student mistake which I think is justified from what we get when searching the docs. If we search “and or Julia” on google, we get, first, this page:
“Mathematical Operations and Elementary Functions…”
which defines bitwise “and” and “or”. These bitwise functions do not behave as a normal user would expect from an and
:
julia> 1 == 1 & 2 == 2
false
(because 1 & 2
takes precedence).
The second page, which is
“Control flow”
defines “Short circuit evaluation”, and then the “&&” and “||” operators, which actually behave as we would expect from “and” and “or”. But that page does not mention that those are the “and” and “or” we would generally want:
julia> 1 == 1 && 2 == 2
true
Thus, I think that the control-flow section would benefit from a very clear explanation that &&
and ||
are the operators that behave as and
and or
operators in other languages (i. e. Python).
(if I had a single saying on the clarity of the Julia syntax, it would be to define and
and or
as synonyms of &&
and ||
).
Edit: Also there are no “help” entries for “and” and “or”:
help?> and
search: tand rand randn expanduser atand asind significand append! LinearIndices transcode lastindex eachindex
Couldn't find and
Perhaps you meant rand, tand, ans, any, end, randn, asind, atand, any!, Any, tan, tanh, abs, all, Cmd, Inf or bind
No documentation found.
Binding and does not exist.
help?> or
search: OrdinalRange for xor sort Core sort! foreach sortperm normpath sortperm! sortslices error export import
Couldn't find or
Perhaps you meant xor, for, Core, sort, one, cos, cot, eof, log, mod, IO, do, X, x, y, !, !=, %, &, ', *, +, - or /
No documentation found.
Binding or does not exist.