7.10 Debugging Recursion

The GAP interpreter monitors the level of nesting of GAP functions during execution. By default, whenever this nesting reaches a multiple of 5000, GAP enters a break loop (break loop) allowing you to terminate the calculation, or enter return; to continue it.

gap> dive:= function(depth) if depth>1 then dive(depth-1); fi; return; end;
function( depth ) ... end
gap> dive(100);
gap> OnBreak:= function() Where(1); end; # shorter traceback
function(  ) ... end
gap> dive(6000);
recursion depth trap (5000)
 at
dive( depth - 1 );
dive( depth - 1 ); called from
...
Entering break read-eval-print loop, you can 'quit;' to quit to outer loop,
or you may return to continue
brk> return;
gap> dive(11000);
recursion depth trap (5000)
 at
dive( depth - 1 );
dive( depth - 1 ); called from
...
Entering break read-eval-print loop, you can 'quit;' to quit to outer loop,
or you may return to continue
brk> return;
recursion depth trap (10000)
 at
dive( depth - 1 );
dive( depth - 1 ); called from
...
Entering break read-eval-print loop, you can 'quit;' to quit to outer loop,
or you may return to continue
brk> return;
gap>

This behaviour can be controlled using the procedure

  • SetRecursionTrapInterval( interval ) F

    interval must be a non-negative small integer (between 0 and 228). An interval of 0 suppresses the monitoring of recursion altogether. In this case excessive recursion may cause GAP to crash.

    gap> dive:= function(depth) if depth>1 then dive(depth-1); fi; return; end;
    function( depth ) ... end
    gap> SetRecursionTrapInterval(1000);
    gap> dive(2500);
    recursion depth trap (1000)
     at
    dive( depth - 1 );
    dive( depth - 1 ); called from
    ...
    Entering break read-eval-print loop, you can 'quit;' to quit to outer loop,
    or you may return to continue
    brk> return;
    recursion depth trap (2000)
     at
    dive( depth - 1 );
    dive( depth - 1 ); called from
    ...
    Entering break read-eval-print loop, you can 'quit;' to quit to outer loop,
    or you may return to continue
    brk> return;
    gap> SetRecursionTrapInterval(-1);
    SetRecursionTrapInterval( <interval> ): <interval> must be a non-negative smal\
    l integer
    not in any function
    Entering break read-eval-print loop, you can 'quit;' to quit to outer loop,
    or You can return a non-negative small integer to continue
    brk> return ();
    SetRecursionTrapInterval( <interval> ): <interval> must be a non-negative smal\
    l integer
    not in any function
    Entering break read-eval-print loop, you can 'quit;' to quit to outer loop,
    or You can return a non-negative small integer to continue
    brk> return 0;
    gap> dive(20000);
    gap> dive(2000000);
    Segmentation fault
    

    [Top] [Previous] [Up] [Index]

    GAP 4 manual
    February 2000