`ParseError` when reducing for short-circuit evaluation

Motive

Hi, I have bit tensors to find fixed point of 3-dimensional ODE and I tried drawing nullcline first. Because intersection of nullcline is a candidate of fixed point, I have to evaluate so many times. I want to use short cirquit evaluation && due to performance issue.

Questions

But I found the operator && couldn’t used in reduce.

  1. Is it intentional? Why && only doesn’t work while & works?
  2. Is there any breakthrough?
julia> reduce(&, [true, false, true])
false

julia> reduce(&&, [true, false, true])
ERROR: ParseError:
# Error @ c:\Users\rmsms\OneDrive\lab\population_dynamics\src\ddm.jl:89:8

reduce(&&, [true, false, true])
#      └┘ ── invalid identifier
Stacktrace:
 [1] top-level scope
   @ c:\Users\rmsms\OneDrive\lab\population_dynamics\src\ddm.jl:89

Enviroment

  • julia v1.10.0
  • windows 11

Not exactly answering your question, but you can use all (which is short-circuiting).

Perhaps obvious, but be sure to construct the iterator (the [true, false, true] in your MWE) so it does not first construct a Vector of Bool (which would evaluate all terms first).

2 Likes

That’s simply because & is a function, but && is not.
Also, this is basically a requirement, because in function calls all arguments are evaluated first.
However, not evaluating arguments in some situations is exactly the purpose of the short-circuit &&.

2 Likes