Evaluate¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
Evaluate[expr]
causes expr to be evaluated even if it appears as the argument of a function whose attributes specify that it should be held unevaluated.
Notes
Evaluate only overrides HoldFirst, HoldRest, and HoldAll attributes when it appears directly as the head of the function argument that would otherwise be held. Evaluate does not override HoldAllComplete. Evaluate with other than one argument reduces to Sequence: Evaluate\[\] gives Sequence\[\] and Evaluate\[a, b\] gives Sequence\[a, b\].Examples (13)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (11)¶
In[1]:= Evaluate[1+1]
Out[1]= 2
In[2]:= Hold[Evaluate[1+1], 2+2]
Out[2]= Hold[2, 2 + 2]
In[3]:= Hold[Evaluate[1+1], Evaluate[2+2], Evaluate[3+3]]
Out[3]= Hold[2, 4, 6]
In[4]:= Hold[f[Evaluate[1+2]]]
Out[4]= Hold[f[Evaluate[1 + 2]]]
In[5]:= Hold[Evaluate[Sin[Pi/6]]]
Out[5]= Hold[1/2]
In[6]:= Hold[Evaluate[2^10]]
Out[6]= Hold[1024]
In[7]:= HoldForm[Evaluate[1+1]]
Out[7]= 2
In[8]:= Hold[Evaluate[Length[{a,b,c}]]]
Out[8]= Hold[3]
In[9]:= Evaluate[Head[{1,2,3}]]
Out[9]= List
In[10]:= Evaluate[]
Out[10]= Sequence[]
In[11]:= Hold[Evaluate[1+1, 2+2]]
Out[11]= Hold[2, 4]
Applications (2)¶
Hold keeps its argument unevaluated
Evaluate forces evaluation even inside the held position
Implementation notes¶
builtin_evaluate (src/core.c) returns a copy of its single argument. Its real effect happens earlier: the evaluator forces Evaluate[expr] arguments to be evaluated even inside a Hold* head's held positions, so by the time the builtin runs the argument is already evaluated and it merely unwraps it.
Protected.Evaluateonly overridesHoldFirst,HoldRest, andHoldAllattributes when it appears directly as the head of the function argument that would otherwise be held.Evaluatedoes not overrideHoldAllComplete.Evaluateworks only on the first level, directly inside a held function. It does not penetrate into deeper subexpressions.- Outside of held contexts,
Evaluateacts as identity. Evaluatewith any number of arguments other than one reduces toSequence:Evaluate[]givesSequence[]andEvaluate[a, b]givesSequence[a, b]. The resultingSequencethen splices wherever it appears, soHold[Evaluate[]]givesHold[]andHold[Evaluate[1+1, 2+2]]givesHold[2, 4].
Attributes: Protected.
References¶
See also: HoldFirst, HoldRest, HoldAll, HoldAllComplete, Sequence
- Source:
src/core.c - Specification:
docs/spec/builtins/expression-information.md - Tests:
tests/test_evaluate.c - Tests:
tests/test_findmin_dogleg.c - Tests:
tests/test_findmin_methods.c - Tests:
tests/test_findmin_neldermead.c
Notes & additional examples¶
Notes¶
Evaluate[expr] forces expr to be evaluated even when it sits in an argument position
that the enclosing head would otherwise hold. In an ordinary (unheld) position it is a
no-op, since the argument has already been evaluated by the standard pipeline ā the C
builtin then just unwraps it.
With more than one argument it splices through Sequence, so Evaluate[a, b] behaves as
Sequence[a, b].