# I don't understand why this code is not working

**URL:** <https://discourse.julialang.org/t/i-dont-understand-why-this-code-is-not-working/37524>\
**Category:** New to Julia\
**Created:** [April 13, 2020, 6:10pm UTC](https://discourse.julialang.org/t/i-dont-understand-why-this-code-is-not-working/37524 "2020-04-13T18:10:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nimpa](https://avatars.discourse-cdn.com/v4/letter/n/eb8c5e/32.png) [@Nimpa](https://discourse.julialang.org/u/Nimpa)\
**Post date:** [April 13, 2020, 6:10pm UTC](https://discourse.julialang.org/t/i-dont-understand-why-this-code-is-not-working/37524/1 "2020-04-13T18:10:28Z")

</div>

The function below is to calculate the fibonacci sequence using get! but i don’t understand why it is not working.

global fib\_cache = Dict{BigInt, BigInt}(0 =\> 0, 1 =\> 1)  
function fib(n::Integer)  
global fib\_cache  
get!(fib\_cache, BigInt(n), fib(n‑1) + fib(n‑2))  
end

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [April 13, 2020, 6:49pm UTC](https://discourse.julialang.org/t/i-dont-understand-why-this-code-is-not-working/37524/2 "2020-04-13T18:49:55Z")

</div>

2 posts were merged into an existing topic: [Why is this code not working?](https://discourse.julialang.org/t/why-is-this-code-not-working/37523/4)

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [April 13, 2020, 6:49pm UTC](https://discourse.julialang.org/t/i-dont-understand-why-this-code-is-not-working/37524/4 "2020-04-13T18:49:04Z")

</div>

Hi @Nimpa, welcome! Looks like you already started a topic for this — let’s try to keep things consolidated there.

> [@Why is this code not working?](https://discourse.julialang.org/t/why-is-this-code-not-working/37523):
>
> The function below is to calculate the fibonacci sequence using get! but i don’t understand why it is not working. global fib\_cache = Dict{BigInt, BigInt}(0 =\> 0, 1 =\> 1) function fib(n::Integer) global fib\_cache get!(fib\_cache, BigInt(n), fib(n‑1) + fib(n‑2)) end

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [April 13, 2020, 6:49pm UTC](https://discourse.julialang.org/t/i-dont-understand-why-this-code-is-not-working/37524/5 "2020-04-13T18:49:08Z")

</div>


