# How do I store a function's results for repeated calls?

In Mathematica one can do this:

```
factors[n_] := factors[n] = FactorInteger[n]
```

Then, the first time you call `factors[2^385-1]`

, the result is computed, stored, and returned. Next time you make the call, no computation is needed, and the result is returned immediately. How do I do this in Sage?

Look up

generatorfunctions and the`yeld`

statement in a Python tutorial...R that this excellent free book has a couple of relevant examples.