[OpenSCAD] Programming in Functional OpenSCAD
doug at moens.org
Wed Jan 31 13:33:37 EST 2018
"I understand what tail recursion is. I'm just not confident about when or
it gets applied in OpenSCAD."
The tail recursion optimization is only applied in two very specific
circumstances. It is not implemented in a general way.
The first case:
function f(x) = shouldExit ? result : f(...);
Note that there is a tail recursive function call after the :
The second case:
function f(x) = keepGoing ? f(...) : result;
Note that there is a tail recursive function call between ? and :
The body of the function must match one of the two patterns. If you change
these patterns in any way (eg, add a 'let' to define local variables), then
the pattern no longer matches, and tail recursion optimization is not
On 31 January 2018 at 13:22, NateTG <nate-openscadforum at pedantic.org> wrote:
> I understand what tail recursion is. I'm just not confident about when or
> it gets applied in OpenSCAD.
> > From a language user point of view, it can be ignored.
> It would be nice if that were true, but the nature of OpenSCAD means that
> things can easily get stack constrained. even when they are working
> properly. For example, Ronaldo didn't modify the tree insertion function
> for some aesthetic reason but rather because stack overflows were a
> practical issue.
> Sent from: http://forum.openscad.org/
> OpenSCAD mailing list
> Discuss at lists.openscad.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Discuss