Hello,
I want to rewrite the following line of code in a way that works without warning in 0.6 and 0.7:
!isdefined(:SAMPLETIME) && const SAMPLETIME = 0.005
The macro @isdefined works on 0.7, but not on 0.6.
Any idea?
Hello,
I want to rewrite the following line of code in a way that works without warning in 0.6 and 0.7:
!isdefined(:SAMPLETIME) && const SAMPLETIME = 0.005
The macro @isdefined works on 0.7, but not on 0.6.
Any idea?
isdefined(@__MODULE__, :SAMPLETIME)
is the closest approximation to the original behavior in most cases.
I tried:
if VERSION >= v"0.7.0"
function isdef(symbol)
return isdefined(@__MODULE__, symbol)
end
@eval using LinearAlgebra
else
function isdef(symbol)
return isdefined(symbol)
end
end
Problem:
On 0.6 I get the error message:
ERROR: LoadError: UndefVarError: @__MODULE__ not defined
Stacktrace:
[1] include_from_node1(::String) at ./loading.jl:576
[2] include(::String) at ./sysimg.jl:14
while loading /media/msata/uavtalk/scripts/analyse_flight.jl, in expression starting on line 33
Any idea?
The following code works on 0.6 and 0.7 without warnings:
@static if VERSION >= v"0.7.0"
function isdef(symbol)
return isdefined(@__MODULE__, symbol)
end
else
function isdef(symbol)
return isdefined(symbol)
end
end
use Compat
and remove all the conditions / function wrappers.
But would that also work with 1.0?
And I would actually prefer to avoid Compat, because that adds another dependency that is updated very often and then requires to recompile all my packages.
Furthermore it is more explicit which old-style functions are still used if I have my own wrappers. They shall be removed in a few months anyway.
Why not? It’s not any different from your version on 1.0.
You don’t have to update Compat just because there’s a new verson out.
That’s a good reason for Compat. It’s very clear which function that you are still using: only one, the Compat
package itself.
Having to remove later is another argument for Compat. Much easier to remove with Compat.
I mean, there’re good reasons Compat exist. If you really don’t like it that’s fine although none of the reasons you give are valid.