# How to check whether a variable is reassignable or not? (e.g. whether it is a function definition)

**URL:** <https://discourse.julialang.org/t/how-to-check-whether-a-variable-is-reassignable-or-not-e-g-whether-it-is-a-function-definition/103276>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 28, 2023, 7:52am UTC](https://discourse.julialang.org/t/how-to-check-whether-a-variable-is-reassignable-or-not-e-g-whether-it-is-a-function-definition/103276 "2023-08-28T07:52:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [August 28, 2023, 7:52am UTC](https://discourse.julialang.org/t/how-to-check-whether-a-variable-is-reassignable-or-not-e-g-whether-it-is-a-function-definition/103276/1 "2023-08-28T07:52:44Z")

</div>

I have a module A and want to copy things from it to module B such that everything can be changed like before (this is needed inside Pluto).

For this goal, I need to know which variable is actually a variable, because it can be reassigned with plain `myvariable = "newvalue"`, or whether it is a function definition, where reassignments fail, but function redefinition like `myvariable() = "newvalue"` work.

Any help how to find out that a variable (given by module and symbol) is reassignable is highly appreciated.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [August 28, 2023, 8:03am UTC](https://discourse.julialang.org/t/how-to-check-whether-a-variable-is-reassignable-or-not-e-g-whether-it-is-a-function-definition/103276/2 "2023-08-28T08:03:54Z")

</div>

Those are all variables, maybe you’re referring to `const` variables where reassignment is either prohibited or warns of errors. Maybe `isconst(::Module, ::Symbol)` works for you.

---

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [August 28, 2023, 8:18am UTC](https://discourse.julialang.org/t/how-to-check-whether-a-variable-is-reassignable-or-not-e-g-whether-it-is-a-function-definition/103276/3 "2023-08-28T08:18:06Z")

</div>

yes, this seems to be it! thank you so much.

for clarity

```plaintext
julia> f() = 4
f (generic function with 1 method)

julia> f = 5
ERROR: invalid redefinition of constant f
Stacktrace:
[1] top-level scope
@ REPL[2]:1

julia> isconst(Main, :f)
true

```

---

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [August 28, 2023, 8:21am UTC](https://discourse.julialang.org/t/how-to-check-whether-a-variable-is-reassignable-or-not-e-g-whether-it-is-a-function-definition/103276/4 "2023-08-28T08:21:53Z")

</div>

is there also a way to distinguish whether assignment would produce a **Warning** vs an **Error**?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 28, 2023, 1:14pm UTC](https://discourse.julialang.org/t/how-to-check-whether-a-variable-is-reassignable-or-not-e-g-whether-it-is-a-function-definition/103276/5 "2023-08-28T13:14:58Z")

</div>

Not that I know of, without actually trying the assignment and catching the error. Warnings are usually Julia being nice and accepting the reassignment, as in

```julia
julia> const foo = 5
5

julia> const foo = 4
WARNING: redefinition of constant foo. This may fail, cause incorrect answers, or produce other errors.
4

```

The current implementation only errors for [a type mismatch](https://github.com/JuliaLang/julia/blob/4768d7ab8fefc8e86c6f9cde09bc10e5a2f72e9b/src/module.c#L899C9-L899C9), so you can test on that, but this is an internal detail that may change at any point.

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [August 28, 2023, 5:21pm UTC](https://discourse.julialang.org/t/how-to-check-whether-a-variable-is-reassignable-or-not-e-g-whether-it-is-a-function-definition/103276/6 "2023-08-28T17:21:22Z")

</div>

See also recent [How to check if variable is a typed global?](https://discourse.julialang.org/t/how-to-check-if-variable-is-a-typed-global/103172)
