# How to use functions defined in package extensions but not the main package?

**URL:** <https://discourse.julialang.org/t/how-to-use-functions-defined-in-package-extensions-but-not-the-main-package/99979>\
**Category:** General Usage\
**Tags:** package-extensions\
**Created:** [June 7, 2023, 12:37am UTC](https://discourse.julialang.org/t/how-to-use-functions-defined-in-package-extensions-but-not-the-main-package/99979 "2023-06-07T00:37:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![singularitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/singularitti/32/17678_2.png) [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Post date:** [June 7, 2023, 12:37am UTC](https://discourse.julialang.org/t/how-to-use-functions-defined-in-package-extensions-but-not-the-main-package/99979/1 "2023-06-07T00:37:57Z")

</div>

I just started using the package extension functionality introduced after v1.9. I am a bit confused about its usage. Can I ask when the package extension is loaded, where are the new functions (which are not defined in the original package) registered?

For example, there are some new functions in [`ext/ForwardDiffStaticArraysExt.jl`](https://github.com/JuliaDiff/ForwardDiff.jl/blob/v0.10.35/ext/ForwardDiffStaticArraysExt.jl) such as [`dualize`](https://github.com/JuliaDiff/ForwardDiff.jl/blob/dc5f08cf3dfac8e7565c697d80afd56ec5986c7c/ext/ForwardDiffStaticArraysExt.jl#L13-L22). How can I use it if I want to (just an example, not that I really need it)? Here are my attempts:

```julia
julia> using ForwardDiff: dualize
ERROR: UndefVarError: `dualize` not defined

julia> using StaticArrays

julia> using ForwardDiff: dualize
ERROR: UndefVarError: `dualize` not defined

julia> using ForwardDiff

julia> names(ForwardDiff)
2-element Vector{Symbol}:
 :DiffResults
 :ForwardDiff

julia> using ForwardDiff.ForwardDiffStaticArraysExt
ERROR: UndefVarError: `ForwardDiffStaticArraysExt` not defined

julia> using ForwardDiffStaticArraysExt
ERROR: ArgumentError: Package ForwardDiffStaticArraysExt not found in current path.
- Run `import Pkg; Pkg.add("ForwardDiffStaticArraysExt")` to install the ForwardDiffStaticArraysExt package.
Stacktrace:
 [1] macro expansion
   @ ./loading.jl:1595 [inlined]
 [2] macro expansion
   @ ./lock.jl:267 [inlined]
 [3] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:1576

```

Are package extensions only used for extending existing methods? Can I define new methods and use them?

Similar to [What things i can/cannot do within an extension?](https://discourse.julialang.org/t/what-things-i-can-cannot-do-within-an-extension/99474)

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [June 8, 2023, 10:35pm UTC](https://discourse.julialang.org/t/how-to-use-functions-defined-in-package-extensions-but-not-the-main-package/99979/2 "2023-06-08T22:35:18Z")

</div>

in the extension:

```julia
f1(x) = 2*x

```

in the package:

```julia
function test_ext(x)
    ext_sym = :Pkg1Ext #the name of the extension
    ext = Base.get_extension(@ __MODULE__ (),ext_sym)
    if ext !== nothing
        return ext.f1(x)
    else
        throw_error("extension not loaded!")
    end
end

```

in your specific case:

```julia
dualize(t,x) = Base.get_extension(ForwardDiff,:ForwardDiffStaticArraysExt).dualize(t,x)

```
