# How to recover \\pi as a constant instead of a variable defined later in julia?

**URL:** <https://discourse.julialang.org/t/how-to-recover-pi-as-a-constant-instead-of-a-variable-defined-later-in-julia/11217>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [May 29, 2018, 4:00am UTC](https://discourse.julialang.org/t/how-to-recover-pi-as-a-constant-instead-of-a-variable-defined-later-in-julia/11217 "2018-05-29T04:00:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![wuhuagumu](https://avatars.discourse-cdn.com/v4/letter/w/7ab992/32.png) [@wuhuagumu](https://discourse.julialang.org/u/wuhuagumu)\
**Post date:** [May 29, 2018, 4:00am UTC](https://discourse.julialang.org/t/how-to-recover-pi-as-a-constant-instead-of-a-variable-defined-later-in-julia/11217/1 "2018-05-29T04:00:52Z")

</div>

I am learning Julia language recently. I defined a

```
\pi=1

```

How can I return to its original value without restarting Julia?

---

<div class="post-metadata">

**Author:** ![Juser](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Juser](https://discourse.julialang.org/u/Juser)\
**Post date:** [May 29, 2018, 4:47am UTC](https://discourse.julialang.org/t/how-to-recover-pi-as-a-constant-instead-of-a-variable-defined-later-in-julia/11217/2 "2018-05-29T04:47:31Z")

</div>

`\pi = Base.\pi`

---

<div class="post-metadata">

**Author:** ![wuhuagumu](https://avatars.discourse-cdn.com/v4/letter/w/7ab992/32.png) [@wuhuagumu](https://discourse.julialang.org/u/wuhuagumu)\
**Post date:** [May 30, 2018, 7:35am UTC](https://discourse.julialang.org/t/how-to-recover-pi-as-a-constant-instead-of-a-variable-defined-later-in-julia/11217/3 "2018-05-30T07:35:07Z")

</div>

This means you now have defined a variable that has the same value as Base.\pi while stored in a different place, right?

---

<div class="post-metadata">

**Author:** ![Juser](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Juser](https://discourse.julialang.org/u/Juser)\
**Post date:** [May 30, 2018, 2:51pm UTC](https://discourse.julialang.org/t/how-to-recover-pi-as-a-constant-instead-of-a-variable-defined-later-in-julia/11217/4 "2018-05-30T14:51:17Z")

</div>

I believe it assigns a pointer to \pi that points to Base.\pi

---

<div class="post-metadata">

**Author:** ![mschauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mschauer/32/13946_2.png) [@mschauer](https://discourse.julialang.org/u/mschauer)\
**Post date:** [May 30, 2018, 3:19pm UTC](https://discourse.julialang.org/t/how-to-recover-pi-as-a-constant-instead-of-a-variable-defined-later-in-julia/11217/5 "2018-05-30T15:19:02Z")

</div>

> This means you now have defined a variable that has the same value as Base.\pi while stored in a different place, right?

I would not worry about that. Mathematical constants are so called singleton types. Base already defines two alias `Base.pi` and `Base.π` and for all purposes they are the same. `Main.π` is actually already an imported binding. These constants do not take up “space”:

```julia
julia> x = Vector{Irrational{:π}}(typemax(Int))
9223372036854775807-element Array{Irrational{:π},1}:
 π = 3.1415926535897...
 π = 3.1415926535897...
 π = 3.1415926535897...
 ...

```

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [May 30, 2018, 3:29pm UTC](https://discourse.julialang.org/t/how-to-recover-pi-as-a-constant-instead-of-a-variable-defined-later-in-julia/11217/6 "2018-05-30T15:29:51Z")

</div>

Some clarification that may be helpful here:

Most Julia functions are imported from a module called `Base`. `Base` is special because all Julia code has an implicit `using Base`. When you start the Julia binary, you are placed into a module called `Main`. Therefore, every time you assign a variable you are assigning variables in the namespace of `Main` (unless you create a `module` block or use `eval` to explicitly evaluate in another module).

So, when you do `π = 1` you are setting the variable `π` in `Main` to no longer reference `Base.π`. Meanwhile, `Base.π` is untouched.

In Julia `module`s are a bit like a cross between a namespace and a class in an OO language (though you should _not_ think of them as classes). They are basically there to provide the functionality of a namespace, but code is allowed to run inside them, sort of as if they each had their own runtime.

> [@wuhuagumu](#):
>
> This means you now have defined a variable that has the same value as Base.\pi while stored in a different place, right?

That’s a good way to think about it from the perspective of modules and namespaces, but it may not be the case in memory (in this case it isn’t). Basically it’s doing what @Juser said.

---

<div class="post-metadata">

**Author:** ![wuhuagumu](https://avatars.discourse-cdn.com/v4/letter/w/7ab992/32.png) [@wuhuagumu](https://discourse.julialang.org/u/wuhuagumu)\
**Post date:** [June 1, 2018, 5:27am UTC](https://discourse.julialang.org/t/how-to-recover-pi-as-a-constant-instead-of-a-variable-defined-later-in-julia/11217/7 "2018-06-01T05:27:06Z")

</div>

Thank you very much. It’s very clear now.
