Let’s say you have a function that calls itself and repeatedly calculates previous results. For instance,
gives this output.
To cache the results, you need to use clojure’s
Now the output looks like this:
In the previous example,
fib 1 was called three times. This example only
executed it once and then cached the result so it didn’t have to compute it