[OpenSCAD] Idea: local var inside list_comprehension
Torsten.Paul at gmx.de
Mon Apr 20 16:38:09 EDT 2015
On 04/20/2015 10:17 PM, nop head wrote:
> Better to optimise tail recursion to be iteration than make the
> language more complicated and ugly. I thought that had already
> been done though?
Simple tail recursion elimination is supported (functions only,
not for modules):
function rec_add(i = 0) = i <= 0 ? 0 : i + rec_add(i - 1);
=> ERROR: Recursion detected calling function 'rec_add'
function tail_rec_add(i = 0, result = 0) = i <= 0 ? result : tail_rec_add(i - 1, result + i);
=> ECHO: 5.0005e+07
Note that there is currently still a limit for the iteration
count, but it's much higher than the limit caused by stack
size for the recursive call.
More information about the Discuss