This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Documentation / Mathematica / Built-in Functions / Programming / Scoping /

Module

FilledSmallSquare Module[x, y, ... , expr] specifies that occurrences of the symbols x, y, ... in expr should be treated as local.

FilledSmallSquare Module[x = , ... , expr] defines initial values for x, ... .

FilledSmallSquare Module allows you to set up local variables with names that are local to the module.

FilledSmallSquare Module creates new symbols to represent each of its local variables every time it is called.

FilledSmallSquare Module creates a symbol with name xxx$nnn to represent a local variable with name xxx. The number nnn is the current value of $ModuleNumber.

FilledSmallSquare The value of $ModuleNumber is incremented every time any module is used.

FilledSmallSquare Before evaluating expr, Module substitutes new symbols for each of the local variables that appear anywhere in expr except as local variables in scoping constructs.

FilledSmallSquare Symbols created by Module carry the attribute Temporary.

FilledSmallSquare Symbols created by Module can be returned from modules.

FilledSmallSquare You can use Module[vars, body /; cond] as the right-hand side of a transformation rule with a condition attached.

FilledSmallSquare Module has attribute HoldAll.

FilledSmallSquare Module is a scoping construct (see Section A.3.8).

FilledSmallSquare Module constructs can be nested in any way.

FilledSmallSquare Module implements lexical scoping.

FilledSmallSquare See Section 1.7.2 and Section 2.7.1.

FilledSmallSquare See also: With, Block, Unique, GeneratedParameters.

FilledSmallSquare New in Version 2.

Further Examples