title: How to do memoization or memoisation in Julia 1.0
body: <p>I have been trying to do memorisation in Julia for the Fibonacci function. This is what I came up with.</p>
  
  <p>The original unmodified code (for control purposes)</p>
  
  <pre><code>function fib(x)
      if x &lt; 3
          return 1
      else
          return fib(x-2) + fib(x-1)
      end
  end
  </code></pre>
  
  <p>This is my first attempt</p>
  
  <pre><code>memory=Dict()
  
  function memfib(x)
      global memory
      if haskey(memory,x)
          return memory[x]
      else
          if x &lt; 3
              return memory[x] = 1
          else
              return memory[x] = memfib(x-2) + memfib(x-1)
          end
      end
  end
  </code></pre>
  
  <p>My second attempt</p>
  
  <pre><code>memory=Dict()
  
  function membetafib(x)
      global memory
      return haskey(memory,x) ? memory[x] : x &lt; 3 ? memory[x]=1 : memory[x] = membetafib(x-2) + membetafib(x-1)
  end
  </code></pre>
  
  <p>My third attempt</p>
  
  <pre><code>memory=Dict()
  
  function memgammafib!(memory,x)
      return haskey(memory,x) ? memory[x] : x &lt; 3 ? memory[x]=1 : memory[x] = memgammafib!(memory,x-2) + memgammafib!(memory,x-1)
  end
  </code></pre>
  
  <p>Are there other ways of doing so that I am not aware of? </p>