Problem with a highly recursive function

2024-07-07 Thread DougT
note that ack(3,14) generates 11452590817 calls to ack. Runs quite a bit faster on 2.0.8 if --mm:refc is used.

Problem with a highly recursive function

2024-07-07 Thread Araq
It's not `refc` as you don't allocate memory anyway, it's the implied `--exceptions` switch. Use a `.quirky` annotation or compile with `--exceptions:setjmp` or compile as C++ (`nim cpp`)...

Problem with a highly recursive function

2024-07-07 Thread giaco
Linked question on stackoverflow

Problem with a highly recursive function

2024-07-06 Thread mratsim
release is needed otherwise GCC/Clang don't enable tail-call optimization (TCO). Your alternatives is either to rewrite the function to be non-recursive, or use a trampoline or find the GCC/Clang flag that triggers TCO.

Problem with a highly recursive function

2024-07-06 Thread Araq
Surely there is a way. Use the Y combinator. :P

Problem with a highly recursive function

2024-07-06 Thread DougT
ack(3,14) runs ok if d:release is used. So the question should be modified to ask if there is a way to run the function without d:release or d:danger

Problem with a highly recursive function

2024-07-06 Thread DougT
The Ackermann function is non primitive recursive (See the wikipedia article). Is there any way to run ack(3,14) without using d:danger. Using -d:nimCallDepthLimit does not work since the value must be a 16 bit int. proc ack(m,n:int) : int = if m == 0 : return n+1