[OpenSCAD] Programming in Functional OpenSCAD

Ronaldo Persiano rcmpersiano at gmail.com
Fri Jan 26 05:21:40 EST 2018


I have already pointed out that it is hard to write non-trivial data
structures in OpenSCAD. I see two main reasons for that: the only intrinsic
data structure in OpenSCAD is list (officially called vector) with very
basic operators and any change in a data structure implies in rewriting all
the structure because of the lack of variables and assignments in OpenSCAD.
Yes, I know that OpenSCAD is not a programming language.

A 2-3 tree is not a trivial data structure and I suspect its implementation
code would be ugly in any programming language. But I think you could
improve your code readability by providing a proper set of atomic functions
to operate over the subjacent node representation. So, your higher level
functions (for insertion for instance) would not be cluttered by operations
on the list components of tree nodes. As an example, the expression:

[node[1],[tree,node[1],[node[2],node[3],node[4]]]]


appearing somewhere in addtreetotreenode function definition seems to be
more readable  (although not always concise) as something like:

let( lval = left_val(node), l2node = left_val(node) )
...

new_2_leaf( lval, new_2_node( tree, lval, l2node ) )



2018-01-26 1:10 GMT-02:00 NateTG <nate-openscadforum at pedantic.org>:

> I just implemented a 2-3 tree using OpenSCAD functions, and it seems pretty
> ugly.  I'm wondering if I'm doing something dumb.   Here's the script:
>
> twothreetree.scad <http://forum.openscad.org/file/t2140/twothreetree.scad>
>
>
>
> --
> 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/20180126/727e5481/attachment-0002.html>


More information about the Discuss mailing list