Once

Once[expr]

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

Details

  • When first used in a session, Once[expr] evaluates expr and returns the result.
  • Subsequent uses of Once[expr] do not evaluate expr again, and return the result from when expr was first evaluated.
  • Once has attribute HoldFirst.
  • Unset[Once[expr]] removes any stored value for Once[expr].

Examples

open allclose all

Basic Examples  (1)

Evaluate an expression inside Once:

In[1]:=
Click for copyable input
Out[1]=

Any subsequent evaluation of Once[expr] simply returns the previous result:

In[2]:=
Click for copyable input
Out[2]=

Applications  (2)

Properties & Relations  (2)

Possible Issues  (2)

See Also

LocalCache  Needs

Introduced in 2016
(11.0)