# Using isdefined in 0.6 and 0.7 without warnings

**URL:** <https://discourse.julialang.org/t/using-isdefined-in-0-6-and-0-7-without-warnings/13669>\
**Category:** General Usage\
**Created:** [August 18, 2018, 5:05pm UTC](https://discourse.julialang.org/t/using-isdefined-in-0-6-and-0-7-without-warnings/13669 "2018-08-18T17:05:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 18, 2018, 5:05pm UTC](https://discourse.julialang.org/t/using-isdefined-in-0-6-and-0-7-without-warnings/13669/1 "2018-08-18T17:05:03Z")

</div>

Hello,  
I want to rewrite the following line of code in a way that works without warning in 0.6 and 0.7:

```julia
!isdefined(:SAMPLETIME) && const SAMPLETIME = 0.005

```

The macro @isdefined works on 0.7, but not on 0.6.

Any idea?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [August 18, 2018, 5:21pm UTC](https://discourse.julialang.org/t/using-isdefined-in-0-6-and-0-7-without-warnings/13669/3 "2018-08-18T17:21:40Z")

</div>

`isdefined(@ __MODULE__ , :SAMPLETIME)` is the closest approximation to the original behavior in most cases.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 18, 2018, 5:48pm UTC](https://discourse.julialang.org/t/using-isdefined-in-0-6-and-0-7-without-warnings/13669/4 "2018-08-18T17:48:24Z")

</div>

I tried:

```julia
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:

```julia
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?

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 18, 2018, 6:27pm UTC](https://discourse.julialang.org/t/using-isdefined-in-0-6-and-0-7-without-warnings/13669/5 "2018-08-18T18:27:17Z")

</div>

The following code works on 0.6 and 0.7 without warnings:

```julia
@static if VERSION >= v"0.7.0"
    function isdef(symbol)
        return isdefined(@ __MODULE__ , symbol)
    end
else
    function isdef(symbol)
        return isdefined(symbol)
    end
end

```

🙂

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [August 18, 2018, 6:50pm UTC](https://discourse.julialang.org/t/using-isdefined-in-0-6-and-0-7-without-warnings/13669/6 "2018-08-18T18:50:50Z")

</div>

use `Compat` and remove all the conditions / function wrappers.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 18, 2018, 8:31pm UTC](https://discourse.julialang.org/t/using-isdefined-in-0-6-and-0-7-without-warnings/13669/7 "2018-08-18T20:31:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [August 18, 2018, 8:52pm UTC](https://discourse.julialang.org/t/using-isdefined-in-0-6-and-0-7-without-warnings/13669/8 "2018-08-18T20:52:16Z")

</div>

> [@ufechner7](#):
>
> But would that also work with 1.0?

Why not? It’s not any different from your version on 1.0.

> [@ufechner7](#):
>
> that is updated very often

You don’t have to update Compat just because there’s a new verson out.

> [@ufechner7](#):
>
> Furthermore it is more explicit which old-style functions are still used if I have my own wrappers.

That’s a good reason for Compat. It’s very clear which function that you are still using: only one, the `Compat` package itself.

> [@ufechner7](#):
>
> They shall be removed in a few months anyway.

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.
