Stack
Details
- Stack[_] shows all expressions currently being evaluated.
- You can call Stack from inside a dialog to see how the dialog was reached. »
- In the list returned by Stack[pattern], each expression is wrapped with HoldCompleteForm. »
- The maximum length of Stack[] is limited by $RecursionLimit. »
- Stack has attribute HoldFirst. »
Examples
open all close allBasic Examples (3)
Print the stack where the Stack command is being evaluated:
f[g[1, Echo[Stack[]];2]]Print the detailed stack contents including function arguments:
f[g[1, Echo[Stack[_]];2]]Display full expressions in the stack, but only those that have head f:
f[g[1, Echo[Stack[_f]];2]]Scope (1)
Use Stack inside of Dialog to see how it was reached:
1 + 2 * Dialog[] + 3 * Dialog[] ^ 2Stack shows that the dialog from 2*Dialog[] is entered first:
Stack[_]Return[x + 1]Upon return from the first dialog, the other is entered:
Stack[_]Return[x - 1]Properties & Relations (3)
Stack gives a list of expressions wrapped in HoldCompleteForm:
InputForm[Stack[_]]Create a version of Factorial that echos the depth of the stack at its innermost point:
f[1] := (Echo[Length[Stack[]]];1)
f[n_Integer] := n f[n - 1]
f[30]The stack is never greater than $RecursionLimit; a TerminatedEvaluation occurs instead:
Table[Block[{$RecursionLimit = 30}, Quiet@f[RandomInteger[{10, 30}]]], 10]Stack has attribute HoldFirst:
Attributes[Stack]See Also
Tech Notes
Related Guides
Related Workflows
- Get a Stack Trace
History
Introduced in 1991 (2.0) | Updated in 2026 (15.0)
Text
Wolfram Research (1991), Stack, Wolfram Language function, https://reference.wolfram.com/language/ref/Stack.html (updated 2026).
CMS
Wolfram Language. 1991. "Stack." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2026. https://reference.wolfram.com/language/ref/Stack.html.
APA
Wolfram Language. (1991). Stack. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Stack.html
BibTeX
@misc{reference.wolfram_2026_stack, author="Wolfram Research", title="{Stack}", year="2026", howpublished="\url{https://reference.wolfram.com/language/ref/Stack.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_stack, organization={Wolfram Research}, title={Stack}, year={2026}, url={https://reference.wolfram.com/language/ref/Stack.html}, note=[Accessed: 12-June-2026]}