I’m trying to use the short circuit conditional from the julia docs and I have a sneaking feeling that this will correct a misapprehension of what is going on. My “thought” is that this should spot that sdmove is an Inf and change it to the number 999.99.
any help appreciated.
In the expression a && b, the subexpression b is only evaluated if a evaluates to true.
Due to the relative priorities of infix operators && and =, this is parsed as
(isinf(sdmove) && sdmove) = 999.99
instead of what you really meant:
isinf(sdmove) && (sdmove = 999.9)
You can use this last expression in order to explicitly set the correct order of operations.
(Opinions on this may vary from one developer to another, but I personally tend to dislike short circuits in cases where the RHS is an assignment, precisely for that reason. But I do like short circuits like isinf(sdmove) && break, because they don’t suffer from the same need for explicit parentheses)
@ffevotte you are a LEGEND. Worked like a champ. Thanks for taking the time. I’ll check out the infix operator precedence for future use. I’ll also give some HARD consideration to taking another coding approach.
BUT I’m trying to stop this error happening. I PROMISE I’ll try though thanks again.
┌ Error: ErrorException("Inf not allowed to be written in JSON spec")
└ @ Stipple /home/dave/.julia/packages/Stipple/qiTHA/src/Stipple.jl:889
The 999.99 was chosen as I’m using the WONDERFUL Stipple.jl and wanted something I can sort. Will certainly bear your advice in mind for later on “when” I get this working.
thanks again
I think this is a right of passage for everyone going from beginner to intermediate level of Julia and working with short circuiting. I went through a very similar headache a while ago.