[OpenSCAD] Programming in Functional OpenSCAD

doug moen 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
how
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
applied.

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
> how
> 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
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20180131/a23f4551/attachment-0002.html>


More information about the Discuss mailing list