Skip to content
← Index | Lesson 1 of 4

@memoize

@memoize — Automatic caching

@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

Search Zolo

9 results

enespt-br