[Scilab-users] How to list the content of the recursion stack?

Jean-Yves Baudais Jean-Yves.Baudais at insa-rennes.fr
Thu May 6 16:36:19 CEST 2021


Hi,

> from
> --> currentMaxDepth = recursionlimit()
> currentMaxDepth =
> 1000.

Thanks Samuel, I didn't know this function. So I face a problem (a bug?): Scilab cratches with segfault but without reaching the recursionlimit. Here the used three functions

function out=test_l(in)
  if in==0 then
    out=in;
    return
  end
  out=in+test_l(in-1);
endfunction

function out=test_ll(in,acc)
  if in<=1
    out=acc;
    return
  end
  out=test_ll(in-1,acc+in);
endfunction

function l_test(in)
  i=1;
  while 1
    mprintf("\n%d: ",i)
    sleep(.5,"s");
    select in
     case 1
      out=test_l(i);
     case 2
      out=test_ll(i,1);
    end
    mprintf("%d\n",out)
    i=i+1;
  end
endfunction

There is no problem with

> recursionlimit(20)
> l_test(1)

The program stops as expected with the message "Limite de récursion atteinte (20)" when i=19 and

> recursionlimit(20)
> l_test(2)

stops when i=20 (I was wrong when I talked about tail call in my previous email!). But, with

> recursionlimit(1000)
> l_test(1)

Scilab cratches at i=41 with segfault and with

> recursionlimit(1000)
> l_test(2)

Scilab cratches at i=140. Is this cratch a know bug? (It's quite far from the recursion limit!)

(Subsidiary question: while l_test(2) stop 1 iteration after l_test(1) with low recursion limit, l_test(2) allows around 100 iterations more than l_test(1) before cratch with recursionlimit(1000)! Where does it comes from?)

--Jean-Yves



More information about the users mailing list