Re: how do I increase the stack limit
Posted: 15 Dec 2017 10:24
There are many reoccurring lines:
Why is it not a tail call? Is it a call to a nondeterm predicate followed by a cut? If so, should the predicate that is called really be nondeterm, or should it perhaps be determ?
There are also certain "standard tricks" to turn non tail calls into tail calls, for example to use accumulator arguments.
Consider calculating the sum of the numbers in an integer list, first using the straightforward way:
This predicate works fine but it cannot be tail call optimized, because the addition is made after the recursive call.
However (since addition is commutative) we can write an auxiliary predicate that uses an accumulator:
This predicate is tail call optimized.
But even when you have considered all such "local" things you may have to reconsider the overall structure of the algorithm. Is it really a necessary/good/correct that the algorithm keeps making these recursive calls? Couls/should it be structured in another way?
So for you should consider what happens in line 32295?main.pro(26072)
main.pro(32280)
main.pro(27268)
main.pro(30882)
main.pro(32295)
main.pro(22555)
main.pro(29139)
main.pro(30935)
main.pro(32295)
main.pro(27242)
main.pro(30882)
main.pro(32295)
main.pro(26832)
main.pro(30844)
main.pro(32295)
main.pro(27485)
main.pro(30882)
main.pro(32295)
main.pro(22555)
main.pro(28187)
main.pro(30912)
main.pro(33476)
main.pro(27074)
main.pro(30864)
main.pro(33476)
main.pro(27409)
main.pro(30882)
main.pro(32295)
main.pro(26588)
main.pro(30821)
main.pro(32095)
main.pro(33380)
main.pro(29968)
main.pro(31015)
main.pro(32295)
main.pro(26832)
main.pro(30844)
main.pro(32295)
main.pro(26832)
main.pro(30844)
main.pro(32295)
main.pro(26832)
main.pro(30844)
main.pro(32295)
main.pro(26832)
Why is it not a tail call? Is it a call to a nondeterm predicate followed by a cut? If so, should the predicate that is called really be nondeterm, or should it perhaps be determ?
There are also certain "standard tricks" to turn non tail calls into tail calls, for example to use accumulator arguments.
Consider calculating the sum of the numbers in an integer list, first using the straightforward way:
Code: Select all
class predicates
sumList : (integer* List) -> integer Sum.
clauses
sumList([]) = 0.
sumList([H | T]) = H + sumList(T).
However (since addition is commutative) we can write an auxiliary predicate that uses an accumulator:
Code: Select all
class predicates
sumList : (integer* List) -> integer Sum.
clauses
sumList(L) = sumList2(L, 0).
class predicates
sumList2 : (integer* List, integer Acc) -> integer Sum.
clauses
sumList2([], Acc) = Acc.
sumList2([H | T], Acc) = sumList(T, H + Acc).
But even when you have considered all such "local" things you may have to reconsider the overall structure of the algorithm. Is it really a necessary/good/correct that the algorithm keeps making these recursive calls? Couls/should it be structured in another way?