HoldAll

HoldAll

is an attribute that specifies that all arguments to a function are to be maintained in an unevaluated form.

Details

  • You can use Evaluate to evaluate the arguments of a HoldAll function in a controlled way.
  • Even when a function has attribute HoldAll, Sequence objects that appear in its arguments are still by default flattened, Unevaluated wrappers are stripped, and upvalues associated with the arguments are used.

Examples

open allclose all

Basic Examples  (1)

Applications  (3)

Many functions with scoping behavior have the HoldAll attribute:

Plotting lists of functions will use separate styling for the different functions:

If the list structure is not manifest, no separate styling is provided:

Use Evaluate to make the list structure manifest:

Different vector-valued functions in a list will still get separate styling:

Use HoldAll and Unevaluated to suppress evaluation of symbols wherever it would occur:

Find the length of a symbol's name even if it has a value:

Implement your own control structure:

Properties & Relations  (13)

Hold is a container with the attribute HoldAll:

Functions that operate on symbols often need the HoldAll attribute:

Without the attribute, they would operate on the symbol's value:

Control structures such as Table protect their arguments from evaluation:

Otherwise, global values might interfere with their operation:

Use Evaluate to force evaluation of an argument of a HoldAll function:

Force evaluation of the right-hand side of a delayed definition:

Use Unevaluated to temporarily treat a function as if it had the attribute HoldAll:

This is the full form of the evaluation result:

This is the full form of the input, before evaluation:

Suppress the evaluation of the arguments of a pure function:

Sequence splicing still happens for functions with the attribute HoldAll:

Use the container HoldComplete to suppress even such transformations:

The attribute that causes this behavior is HoldAllComplete:

Substitution works inside a held expression:

Insert into a held expression:

NHoldAll protects arguments from N but evaluates them normally otherwise:

HoldPattern protects patterns from evaluation but does not interfere with pattern matching:

Wolfram Research (1988), HoldAll, Wolfram Language function, https://reference.wolfram.com/language/ref/HoldAll.html.

Text

Wolfram Research (1988), HoldAll, Wolfram Language function, https://reference.wolfram.com/language/ref/HoldAll.html.

CMS

Wolfram Language. 1988. "HoldAll." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/HoldAll.html.

APA

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

BibTeX

@misc{reference.wolfram_2024_holdall, author="Wolfram Research", title="{HoldAll}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/HoldAll.html}", note=[Accessed: 13-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_holdall, organization={Wolfram Research}, title={HoldAll}, year={1988}, url={https://reference.wolfram.com/language/ref/HoldAll.html}, note=[Accessed: 13-December-2024 ]}