Hold
Hold
Hold[ expr ] keeps an expression unexecuted, so that the commands in it are executed later.
Usages
Hold[ expr ]
Hold[ expr ] keeps expr as it is: commands inside it are not executed. Script variables inside expr are replaced by their values. Hold is mainly used to pass a mapping with commands to another command, such as Map or Select, which then executes the commands for each element.
| Example | in | out |
|---|---|---|
The command inside Hold is not executed. |
Hold[ CalcPlus[1, 2] ] |
Hold[CalcPlus[1, 2]] |
| Script variables are replaced by their values. | a := 3 |
r = Hold[3+1] |
A mapping with a command, used in Map: RandomInt is executed for each element. |
f := Hold[x -> RandomInt[{1, x}]] |
for example r = {2, 4} |
A condition for Select. |
Select[ Hold[x -> Type[x] == Variable], 2x + 3y ] |
{x, y} |
Details
Simplifydoes not removeHold:Simplify[ Hold[CalcPlus[1, 2]] ]staysHold[CalcPlus[1, 2]].- Do not show an expression with
Holdto students: it is displayed with the word "Hold", as .
See also: Map, Select, CreateMapping