Initialization

Initialization

is an option for notebooks, cells, Dynamic, DynamicModule, Manipulate and related constructs that specifies an expression to be evaluated when the construct is first displayed.

Details

  • The typical usage is Initialization:>expr.
  • Initialization expressions defined in particular cells in a notebook are evaluated when those cells are first made visible, and not necessarily when the notebook is first opened.
  • Initialization expressions are guaranteed to be evaluated exactly once before the contents of the main construct are resolved.
  • An object that is already initialized can be initialized again if it is deleted, then restored as a result of using Undo. If an object is copied and pasted, each pasted copy will initialize again.
  • Initialization expressions may be applied directly to notebooks and cells. Unlike most other option values, the Initialization option of a cell will not inherit any settings applied at the notebook level.

Examples

open allclose all

Basic Examples  (4)

Specify an expression to be evaluated before displaying Dynamic:

DynamicModule:

Manipulate:

For a notebook:

Properties & Relations  (3)

Initialization is guaranteed to only happen once:

Initialization for outer constructs occurs before initialization for inner constructs:

Each time a Dynamic destroys and recreates an initializing construct, the initialization will run again:

Possible Issues  (3)

Loading a package in the initialization does not allow you to use unqualified symbols from that package:

Doing this properly requires loading the package in the Input cell and loading it in an outer initialization:

This function produces a cell indicating the current Initialization setting upon that cell:

Unlike most options, cells do not inherit Initialization from the notebook setting:

Cells still inherit Initialization from named cell styles:

Wolfram Research (2007), Initialization, Wolfram Language function, https://reference.wolfram.com/language/ref/Initialization.html (updated 2020).

Text

Wolfram Research (2007), Initialization, Wolfram Language function, https://reference.wolfram.com/language/ref/Initialization.html (updated 2020).

BibTeX

@misc{reference.wolfram_2020_initialization, author="Wolfram Research", title="{Initialization}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/Initialization.html}", note=[Accessed: 21-January-2021 ]}

BibLaTeX

@online{reference.wolfram_2020_initialization, organization={Wolfram Research}, title={Initialization}, year={2020}, url={https://reference.wolfram.com/language/ref/Initialization.html}, note=[Accessed: 21-January-2021 ]}

CMS

Wolfram Language. 2007. "Initialization." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/Initialization.html.

APA

Wolfram Language. (2007). Initialization. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Initialization.html