WLJS LogoWLJS Notebook

Once

Once[expr] evaluates expr once in each Wolfram Language session, always returning the result from the first evaluation.

  • Once[expr, loc] evaluates expr once and caches the result in persistence location loc.

Examples

Evaluate an expression only once:

Once[Print["Evaluated!"; RandomReal[]]]
(* Prints "Evaluated!" only the first time *)

Cache result persistently:

Once[RandomReal[], "Local"]

Use for expensive computations:

data = Once[Import["https://example.com/large-dataset.csv"]];

Please visit the official Wolfram Language Reference for more details.

On this page