Scoping Constructs

The flexibility of Mathematica's symbolic architecture is reflected in its rich collection of carefully defined constructs for localization and modularization. The use of multiple forms of scoping allows for more elegant, readable, and efficient programs, supports the concept of programs as data, and allows direct correspondence with mathematical notions of variables.

ReferenceReference

With evaluate with specified variables replaced by values

Module localize names of variables (lexical scoping)

Block localize values of variables (dynamic scoping)

DynamicModule localize names of variables in dynamic interface constructs

Constructs with Automatic Name Scoping

Function a pure function, with formal variables automatically scoped

Rule (->), RuleDelayed (:>) — named pattern variables automatically scoped

Set (=), SetDelayed (:=) — named pattern variables automatically scoped

Constructs with Automatic Value Scoping

Table create a table, with iterator variables automatically scoped

Do ▪ Sum ▪ Plot ▪ Plot3D ▪ NDSolve ▪

Other Forms of Scoping

Begin, End localize symbol namespace

Throw, Catch localize exceptions

Quiet, Check localize messages

BlockRandom localize pseudorandom variables

New to Mathematica? Find your learning path »
Have a question? Ask support »