How to define a function that remembers values?

Memoization and precomputation have different purposes. You memoize a function if the arguments are not necessarily known in advance (or you don’t want to bother thinking about them), while precomputation helps you when a calculation can be broken down to stages, and one of these stages is reusable (and expensive). In some contexts, both are helpful.

2 Likes