Help / Release / J 6.01 / Recursion Limit Changed

From J Wiki
Jump to navigation Jump to search


>> << Pri JfC LJ Phr Dic Voc !: Rel NuVoc wd Help Release



Recursion Limit Changed

initial writing: 2006-02-20
last updated: 2006-06-08


When the recursion limit (function call depth limit) is exceeded, a stack error is signalled. Previously a limit error is signalled. Moreover, instances of J crashing due to a stack error has been greatly reduced.

The recursion limit is exceeded when the total depth of the called functions is larger than the limit, where the depth of a function is roughly the depth of its tree representation (5!:4). For example:

   g=: 3 : 'g c=:>:y'
   g 0
|stack error: g
|       g c=:>:y
   c
9999

   ".t=: '".t [ c=:>:c' [ c=: 0
|stack error
|       ".t[c=:>:c
   c
19999

   (+/i.1+c) -: (0:`(+ $:@<:)@.*) c=: 4999
1
   (+/i.1+c) -: (0:`(+ $:@<:)@.*) c=: 5000
|stack error
|   (+/i.1+c)-:    (0:`(+$:@<:)@.*)c=:5000

The recursion limit is reduced when debug mode is on (13!:0 ]1), to enable the debug facility itself to be run when a stack error is signalled.

The recursion limit is constrained by the stack size available to the J executable file. Crashes due to stack errors can be overcome by increasing the stack size. Under Windows, the stack size can be queried and set as follows:

   dumpbin /headers       c:\j601\j.exe
   editbin /stack:6000000 c:\j601\j.exe

The stack size is called “size of stack reserve” in the dumpbin output. The stack space can also be interrogated in J as follows:

   ss=: 256 #. a. i. +&3 2 1 0@[ { 1!:1@]
   368 ss <'c:\j601\j.exe'
5000000
   360 ss <'c:\j504\j.exe'
5000000

The right argument to ss is the name of the J executable file; the left argument is the location in the file of the 4-byte word that specifies the stack size. (The location varies with the file, and the word is in reverse byte order for Windows.)



>> << Pri JfC LJ Phr Dic Voc !: Rel NuVoc wd Help Release