$RecursionLimit

$RecursionLimit

gives the current limit on the number of levels of recursion that the Wolfram Language can use.

Details

  • $RecursionLimit=n sets the limit on the number of recursion levels that the Wolfram Language can use to be n.
  • $RecursionLimit=Infinity removes any limit on the number of recursion levels.
  • $RecursionLimit gives the maximum length of the stack returned by Stack[].
  • Each time the evaluation of a function requires the nested evaluation of the same or another function, one recursion level is used up.
  • On most computers, each level of recursion uses a certain amount of stack space. $RecursionLimit allows you to control the amount of stack space that the Wolfram Language can use from within the Wolfram Language. On some computer systems, your whole Wolfram Language session may crash if you allow it to use more stack space than the computer system allows.
  • MemoryInUse and related functions do not count stack space.

Examples

open allclose all

Basic Examples  (2)

$RecursionLimit limits infinite recursion with circular definitions:

Temporarily reset $RecursionLimit:

Scope  (1)

The recursion limit can be set to to allow any number of recursion steps:

Properties & Relations  (2)

The recursion limit protects against recursive runaway definitions:

The iteration limit protects against runaway definitions:

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

Text

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

CMS

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

APA

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

BibTeX

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

BibLaTeX

@online{reference.wolfram_2024_$recursionlimit, organization={Wolfram Research}, title={$RecursionLimit}, year={1988}, url={https://reference.wolfram.com/language/ref/$RecursionLimit.html}, note=[Accessed: 21-December-2024 ]}