# OpenSCAD programming question, recursion, functions, and modules

7 messages
Open this post in threaded view
|

## OpenSCAD programming question, recursion, functions, and modules

Open this post in threaded view
|

## Re: OpenSCAD programming question, recursion, functions, and modules

Open this post in threaded view
|

## Re: OpenSCAD programming question, recursion, functions, and modules

Open this post in threaded view
|

## Re: OpenSCAD programming question, recursion, functions, and modules

Open this post in threaded view
|

## Re: OpenSCAD programming question, recursion, functions, and modules

 In reply to this post by DanS If you want to collect all 2D points in a list, whatever depth it has in it, this may help you:function get_2D_points(L,n=0,res=[]) =  n>=len(L) ?    res  : L[n]*0==[0,0] ?       get_2D_points(L,n+1, concat(res,[L[n]]))    : get_2D_points(L,n+1, get_2D_points(L[n],0,res));  l = [[1,2],[[3,4],[[5,6]]],[[[[7,8]],[9,10]]],[11,12]];  echo( get_2D_points(l));// ECHO: [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]]​However, this function crashes if the list is not a nested list of 2D points like  [[1,2], 3] or [1,2,3].or ["a"], etc.2018-02-08 22:23 GMT-02:00 Dan Shriver :on 2) the wiki book says that concat() does not change the levels, just tacks one on to another.  Because of recursion I will have a heterogeneous list which has points and also members that are lists of points...like this (ignore the values they are nonsense)[  [ (4,7), (8,2), (7,8) ] (1,2), (5,10), (3,8) [ (11,21), (15,10), (3,18) ] ]and I want to flatten it into a one dimensional list (not a list of lists... which will have nested lists up to how many times I am recursing)like this [   (4,7), (8,2), (7,8)  (1,2), (5,10), (3,8)  (11,21), (15,10), (3,18)  ] _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org