# Redefine Function as Variable

**URL:** <https://discourse.julialang.org/t/redefine-function-as-variable/29786>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [October 11, 2019, 5:01pm UTC](https://discourse.julialang.org/t/redefine-function-as-variable/29786 "2019-10-11T17:01:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![duncanam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/duncanam/32/10669_2.png) [@duncanam](https://discourse.julialang.org/u/duncanam)\
**Post date:** [October 11, 2019, 5:01pm UTC](https://discourse.julialang.org/t/redefine-function-as-variable/29786/1 "2019-10-11T17:01:00Z")

</div>

Often I used my REPL for testing and scratch work. Thus, the variable x gets bound to quite a few things and I redefine it often. However, if I do:

```julia
function x(y)
return y+1
end

```

and then later try

```julia
x = 5

```

I am hit with:

```julia
ERROR: invalid redefinition of constant x

```

Looking online, I see that the workspace() function would have taken care of this nicely, but this is no longer available. Additionally, I can’t do:

```julia
x=nothing
GC.gc()

```

as I get the same error. (and apparently gc() doesn’t work anymore either). Any suggestions as to how I can circumvent this? I’d really not like to have to close out of the REPL. There are times I have packages precompiled and waiting a few minutes every time I run into this is somewhat annoying.

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [October 11, 2019, 5:02pm UTC](https://discourse.julialang.org/t/redefine-function-as-variable/29786/2 "2019-10-11T17:02:59Z")

</div>

Try defining the function inside a module. See [Workflow Tips · The Julia Language](https://docs.julialang.org/en/v1/manual/workflow-tips/).

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [October 11, 2019, 6:22pm UTC](https://discourse.julialang.org/t/redefine-function-as-variable/29786/3 "2019-10-11T18:22:30Z")

</div>

FWIW, the reason `workspace` used to be unreliable which ultimately lead to its removal (package being loaded into Main) has been changed so, and while I can’t speak for everyone, I would at least personally like to have it back.

Someone with the desire to do so could perhaps take a look at the PR that removed it and try to undo it.

---

<div class="post-metadata">

**Author:** ![duncanam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/duncanam/32/10669_2.png) [@duncanam](https://discourse.julialang.org/u/duncanam)\
**Post date:** [October 11, 2019, 6:44pm UTC](https://discourse.julialang.org/t/redefine-function-as-variable/29786/4 "2019-10-11T18:44:44Z")

</div>

Thanks, this is a great way to keep things separate and modular.
