[OpenSCAD] Programming in Functional OpenSCAD

doug moen doug at moens.org
Fri Jan 26 14:05:05 EST 2018

As Ronaldo says, "OpenSCAD is not a programming language". It's missing
features that would make this kind of programming easier and more
comfortable. I don't like calling OpenSCAD a functional programming
language, because it's missing many of the features that you expect in a
functional language, such as function values.

OpenSCAD uses reference counting for memory management.

You wrote:


You could make the code shorter by writing


I don't claim this is easier to understand, but it it is shorter.

This kind of code is hard to read, because of all of the "magic number"


It would be better to use names, instead of numbers. Ronaldo suggests using
helper functions. I tend to use named constants as indexes into lists that
actually structures/records, kind of like this:

BRANCH1 = 0;
VALUE1 = 1;
BRANCH2 = 2;
VALUE2 = 3;
BRANCH3 = 4;

[ treenode[BRANCH1],
  [ treenode[BRANCH2][BRANCH1], treenode[BRANCH2][VALUE1],
treenode[BRANCH2][BRANCH2] ],
  [ treenode[BRANCH2][BRANCH3], treenode[VALUE2], treenode[BRANCH3][VALUE1]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20180126/cad1e92b/attachment-0002.html>

More information about the Discuss mailing list