# Is there a way to test if something \`isexported()\`?

**URL:** https://discourse.julialang.org/t/is-there-a-way-to-test-if-something-isexported/8139
**Category:** General Usage
**Tags:** question
**Created:** [January 3, 2018, 11:19pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-test-if-something-isexported/8139 "2018-01-03T23:19:17Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)
#### Post date: [January 3, 2018, 11:19pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-test-if-something-isexported/8139/1 "2018-01-03T23:19:17Z")

</div>

Sometimes `isdefined` is a little too loose.

Is there a way to see if a variable is explicitly exported by a module?

* * *

Example:

```nohighlight
# src/FizzBuzz.jl

module FizzBuzz
   export foo
   foo() = println("hello")
   bar() = println("world")
end

```

```nohighlight
# Julia REPL

> isdefined(FizzBuzz, :foo)
true

> isdefined(FizzBuzz, :bar)
true

> isexported(FizzBuzz, :foo)
true

> isexported(FizzBuzz, :bar)
false

```

---

<div class="post-metadata">

### Author: ![raminammour](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raminammour/32/13572_2.png) [@raminammour](https://discourse.julialang.org/u/raminammour)
#### Post date: [January 3, 2018, 11:41pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-test-if-something-isexported/8139/2 "2018-01-03T23:41:39Z")

</div>

`Base.isexported` on `0.6` ?

---

<div class="post-metadata">

### Author: ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)
#### Post date: [January 3, 2018, 11:44pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-test-if-something-isexported/8139/3 "2018-01-03T23:44:22Z")

</div>

That’s exactly what I wanted. How did you find out about that? (it’s not in the docs)

---

<div class="post-metadata">

### Author: ![raminammour](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raminammour/32/13572_2.png) [@raminammour](https://discourse.julialang.org/u/raminammour)
#### Post date: [January 3, 2018, 11:50pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-test-if-something-isexported/8139/4 "2018-01-03T23:50:10Z")

</div>

Just by accident :), I assumed that they must have it to define what to bring into the Main module after `using FizzBuzz`, so I looked in `Base` and `Core`.

```julia
julia> isdefined(Base,:isexported)
true

julia> Base.isexported(Base,:isexported)
false

```

---

<div class="post-metadata">

### Author: ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)
#### Post date: [January 4, 2018, 10:53pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-test-if-something-isexported/8139/5 "2018-01-04T22:53:05Z")

</div>

Maybe this is stupid idea:

```julia
julia> [i for i in names(Base, true) if contains(string(i), "exported")]
4-element Array{Symbol,1}:
 Symbol("#is_exported_from_stdlib")
 Symbol("#isexported")             
 :is_exported_from_stdlib          
 :isexported  

```

But using undocumented features could be bad idea too…

---

<div class="post-metadata">

### Author: ![raminammour](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raminammour/32/13572_2.png) [@raminammour](https://discourse.julialang.org/u/raminammour)
#### Post date: [January 4, 2018, 11:18pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-test-if-something-isexported/8139/6 "2018-01-04T23:18:29Z")

</div>

Here is an implementation using `names` which is documented:

```julia
isexported(m::Module,s::Symbol)=(s \in names(m,true)) && (s \in names(m))

```

(I could not get the `\in` tab to get the right symbol)

---

<div class="post-metadata">

### Author: ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)
#### Post date: [January 5, 2018, 2:20am UTC](https://discourse.julialang.org/t/is-there-a-way-to-test-if-something-isexported/8139/7 "2018-01-05T02:20:03Z")

</div>

Implementation in Base is this:

```julia
isexported(m::Module, s::Symbol) = ccall(:jl_module_exports_p, Cint, (Any, Any), m, s) != 0 

```

Sorry but your implementation doesn’t work. According to doc `names(m)` is subset of `names(m, true)` which makes part of your code redundant. Also exported deprecated symbols are ignored. See:

```julia
#Julia 0.7
julia> isexported(m::Module,s::Symbol)=(s ∈ names(m,true)) && (s ∈ names(m))
isexported (generic function with 1 method)

julia> isexported(Base, :zeta)
false

julia> Base.isexported(Base, :zeta)
true

```

---

<div class="post-metadata">

### Author: ![raminammour](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raminammour/32/13572_2.png) [@raminammour](https://discourse.julialang.org/u/raminammour)
#### Post date: [January 5, 2018, 3:26pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-test-if-something-isexported/8139/8 "2018-01-05T15:26:44Z")

</div>

You are right about the `names` so the the two are redundant (I misunderstood `names`, I wanted something that almost can tell if it is defined/undefined, and then decide if it is exported).

Now, weirdly on `0.6`:

```julia
julia> isexported(Base,:zeta)
true

julia> Base.isexported(Base,:zeta)
true

```

I don’t have `0.7` but I thought that special functions where taken out from `Base` in `0.7`.

---

<div class="post-metadata">

### Author: ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)
#### Post date: [January 5, 2018, 5:02pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-test-if-something-isexported/8139/9 "2018-01-05T17:02:49Z")

</div>

Maybe I am wrong. I tried to simulate deprecated symbol. And zeta on 0.6 is working without deprecation message:

```julia
julia> zeta(0)
-0.5

```

and on 0.7 deprecation is faked up:

```julia
julia> zeta(0)
ERROR: Base.zeta has been moved to the package SpecialFunctions.jl.
Run `Pkg.add("SpecialFunctions")` to install it, restart Julia,
and then run `using SpecialFunctions` to load it.
Stacktrace:
 [1] error(::Function, ::String, ::String, ::String, ::String, ::String, ::String, ::String, ::String, ::String) at ./error.jl:42
 [2] #zeta#852(::Base.Iterators.IndexValue{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Int64, ::Vararg{Int64,N} where N) at ./deprecated.jl:142
 [3] zeta(::Int64, ::Vararg{Int64,N} where N) at ./deprecated.jl:142
 [4] top-level scope

```

So I tried to find really deprecated symbol on 0.6:

```julia
julia> ipermutedims([1 2;3 4], (2,1))
┌ Warning: `ipermutedims(A::AbstractArray, p)` is deprecated, use `permutedims(A, invperm(p))` instead.
│ caller = top-level scope
└ @ Core :0
2×2 Array{Int64,2}:
 1 3
 2 4

julia> Base.isexported(Base, :ipermutedims)
true

```

but:

```julia
julia> :ipermutedims in names(Base)
true

```

So it seems I don’t understand what is doc saying:

```julia
help?> names

```

Get an array of the names exported by a Module, **excluding deprecated names.**
