NonStandard Evaluation

While most builtin Wolfram Language functions follow the standard evaluation procedure, some important ones do not. For example, most of the Wolfram Language functions associated with the construction and execution of programs use nonstandard evaluation procedures. In typical cases, the functions either never evaluate some of their arguments, or do so in a special way under their own control.

x=ydo not evaluate the lefthand side
If[p,a,b]evaluate a if p is True, and b if it is False
Do[expr,{n}]evaluate expr n times
Plot[f,{x,}]evaluate f with a sequence of numerical values for x
Function[{x},body]do not evaluate until the function is applied

Some functions that use nonstandard evaluation procedures.

When you give a definition such as a=1, the Wolfram Language does not evaluate the a that appears on the lefthand side. You can see that there would be trouble if the a was evaluated. The reason is that if you had previously set a=7, then evaluating a in the definition a=1 would put the definition into the nonsensical form 7=1.

In the standard evaluation procedure, each argument of a function is evaluated in turn. This is prevented by setting the attributes HoldFirst, HoldRest and HoldAll. These attributes make the Wolfram Language "hold" particular arguments in an unevaluated form.

HoldFirstdo not evaluate the first argument
HoldRestevaluate only the first argument
HoldAllevaluate none of the arguments

Attributes for holding function arguments in unevaluated form.

With the standard evaluation procedure, all arguments to a function are evaluated:
Click for copyable input
This assigns the attribute HoldFirst to h:
Click for copyable input
The first argument to h is now held in an unevaluated form:
Click for copyable input
When you use the first argument to h like this, it will get evaluated:
Click for copyable input
Builtin functions like Set carry attributes such as HoldFirst:
Click for copyable input

Even though a function may have attributes which specify that it should hold certain arguments unevaluated, you can always explicitly tell the Wolfram Language to evaluate those arguments by giving the arguments in the form Evaluate[arg].

Evaluate effectively overrides the HoldFirst attribute, and causes the first argument to be evaluated:
Click for copyable input
f[Evaluate[arg]]evaluate arg immediately, even though attributes of f may specify that it should be held

Forcing the evaluation of function arguments.

By holding its arguments, a function can control when those arguments are evaluated. By using Evaluate, you can force the arguments to be evaluated immediately, rather than being evaluated under the control of the function. This capability is useful in a number of circumstances.

The Wolfram Language Set function holds its first argument, so the symbol a is not evaluated in this case:
Click for copyable input
You can make Set evaluate its first argument using Evaluate. In this case, the result is the object which is the value of a, namely b is set to 6:
Click for copyable input
b has now been set to 6:
Click for copyable input

In most cases, you want all expressions you give to the Wolfram Language to be evaluated. Sometimes, however, you may want to prevent the evaluation of certain expressions. For example, if you want to manipulate pieces of a Wolfram Language program symbolically, then you must prevent those pieces from being evaluated while you are manipulating them.

You can use the functions Hold and HoldForm to keep expressions unevaluated. These functions work simply by carrying the attribute HoldAll, which prevents their arguments from being evaluated. The functions provide "wrappers" inside which expressions remain unevaluated.

The difference between Hold[expr] and HoldForm[expr] is that in standard Wolfram Language output format, Hold is printed explicitly, while HoldForm is not. If you look at the full internal Wolfram Language form, you can however see both functions.

Hold maintains expressions in an unevaluated form:
Click for copyable input
HoldForm also keeps expressions unevaluated, but is invisible in standard Wolfram Language output format:
Click for copyable input
HoldForm is still present internally:
Click for copyable input
The function ReleaseHold removes Hold and HoldForm, so the expressions they contain get evaluated:
Click for copyable input
Hold[expr]keep expr unevaluated
HoldComplete[expr]keep expr unevaluated and prevent upvalues associated with expr from being used
HoldForm[expr]keep expr unevaluated, and print without HoldForm
ReleaseHold[expr]remove Hold and HoldForm in expr
Extract[expr,index,Hold]get a part of expr, wrapping it with Hold to prevent evaluation

Functions for handling unevaluated expressions.

Parts of expressions are usually evaluated as soon as you extract them:
Click for copyable input
This extracts a part and immediately wraps it with Hold, so it does not get evaluated:
Click for copyable input
f[,Unevaluated[expr],]give expr unevaluated as an argument to f

Temporary prevention of argument evaluation.

1+1 evaluates to 2, and Length[2] gives 0:
Click for copyable input
This gives the unevaluated form 1+1 as the argument of Length:
Click for copyable input

Unevaluated[expr] effectively works by temporarily giving a function an attribute like HoldFirst, and then supplying expr as an argument to the function.

SequenceHolddo not flatten out Sequence objects that appear as arguments
HoldAllCompletetreat all arguments as completely inert

Attributes for preventing other aspects of evaluation.

By setting the attribute HoldAll, you can prevent the Wolfram Language from evaluating the arguments of a function. But even with this attribute set, the Wolfram Language will still do some transformations on the arguments. By setting SequenceHold you can prevent it from flattening out Sequence objects that appear in the arguments. And by setting HoldAllComplete you can also inhibit the stripping of Unevaluated, and prevent the Wolfram Language from using any upvalues it finds associated with the arguments.