You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently, I was trying to scale a variable f and subtract x from it, 2*f - x. Without * and spaces, that leads to a malformed expression error:
julia>mirror(f, x) = x > f ? (2f - x) : x
mirror (generic function with 1 method)
julia>mirror(f, x) = x > f ? (2*f-x) : x
mirror (generic function with 1 method)
julia>mirror(f, x) = x > f ? (2f-x) : x
ERROR: syntax: malformed expression
Stacktrace:
[1] top-level scope
@ none:1
It took me a while to figure out that Julia was trying to parse this as a Float32 where f seperates mantissa from exponent, e.g. 2f-3. A better error message would have helped me a lot, e.g. cannot parse expression as Float32. Then, the docstring of Float32 would reveal the use of f that I didn't have in mind.
Would it be reasonable to parse 2f-X as 2f - X if X is anything but a number?
This would make 2f-x behave as expected.
Side note: if there is a variable f around, this leads to some interesting situations:
julia> f =1010
julia>2f +121
julia>2*f+121
julia>2f+120.0f0
julia>2f+1f # (2f+1)*f200.0f0
The text was updated successfully, but these errors were encountered:
Recently, I was trying to scale a variable
f
and subtractx
from it,2*f - x
. Without*
and spaces, that leads to amalformed expression
error:It took me a while to figure out that Julia was trying to parse this as a
Float32
wheref
seperates mantissa from exponent, e.g.2f-3
. A better error message would have helped me a lot, e.g.cannot parse expression as Float32
. Then, the docstring ofFloat32
would reveal the use off
that I didn't have in mind.Would it be reasonable to parse
2f-X
as2f - X
ifX
is anything but a number?This would make
2f-x
behave as expected.Side note: if there is a variable
f
around, this leads to some interesting situations:The text was updated successfully, but these errors were encountered: