Decorators · 7.1
@memoize
All lessons are open — jump whenever you need.
@memoize stores results of previous calls:
@memoize
fn fib(n: int) -> int {
if n <= 1 { return n }
return fib(n-1) + fib(n-2)
}
// First call: computes
// Second call: returns from cache
print(fib(40)) // instant!Goal: Add @memoize to the fib function and compute fib(30).
lesson-7-1.zolo
Program output
Run the code to see the output