We can call the add operator as
Base.:+. Can I do the same to logical and?
julia> Base.:+(3, 4)
julia> Base.:&&(true, false)
ERROR: UndefVarError: && not defined
 getproperty(x::Module, f::Symbol)
@ Base .\Base.jl:31
 top-level scope
julia> true && false
I don’t think so.
&& is actually control flow, like
? not simply a function like
Due to having short-circuiting behavior
You can use the function
all, for instance
Thanks. I actually want the Boolean operators: and, or, not.
Interestingly, I just realized that the bitwise operations can work here.
julia> Base.:&(1, 0)
julia> Base.:&(1, 1)
julia> Base.:&(true, false)
julia> Base.:&(true, true)
julia> Base.:|(true, true)
julia> Base.:|(true, false)
ah yes, the when applied to
& is exactly equal to “logical and”
As has been vaguely hinted, the issue here is that
|| are actually control flow constructs (like
if) rather than functions (like
+). But yes, some combination of
any is what you’re after.
Of course, you can always make your own functions if you need. For example,
(x,y) -> x && y would have worked. But you should obviously just use
Base.:& here, and new functions will not
allow you to extend do not change the behavior of change the behavior of
Base.:& to new types
Base.:& (edited for clarity).
Not sure I follow - you’re very much able to define methods on new types for
&. It’s a function like any other.