ApplyTo

ApplyTo[x,f] or x//=f

computes f[x] and resets x to the result.

Details

  • ApplyTo[x,f] is effectively equivalent to x=x//f or x=f[x].
  • ApplyTo has attribute HoldFirst.
  • In ApplyTo[x,f], x can be a symbol or other expression with an existing value. »

Examples

open allclose all

Basic Examples  (1)

Create a variable with a value:

Use ApplyTo to compute f[x]:

The result is stored in x:

Scope  (5)

Use ApplyTo with an operator form:

Use ApplyTo with Function:

Use ApplyTo with Composition:

Use ApplyTo with RightComposition:

The first argument to ApplyTo need not be a symbol:

Applications  (2)

Use ApplyTo to swap two elements of a list:

The 3 and 5 have been swapped in list:

Construct a matrix:

Use ApplyTo to evaluate the Sin of the second column:

The column was modified in place:

Properties & Relations  (3)

ApplyTo is a combination of Set and function application:

Equivalently, using postfix notation:

ApplyTo can be viewed as the assignment form of Construct:

ApplyTo is a generalization of AddTo, AppendTo and similar functions:

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

Text

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

CMS

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

APA

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

BibTeX

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

BibLaTeX

@online{reference.wolfram_2024_applyto, organization={Wolfram Research}, title={ApplyTo}, year={2020}, url={https://reference.wolfram.com/language/ref/ApplyTo.html}, note=[Accessed: 21-December-2024 ]}