Add multiple items to a flat list in a loop.

4 messages
Open this post in threaded view
|

Add multiple items to a flat list in a loop.

 This one is a beginners thing for sure but after 4 hours head scratching... Consider this simple loop that produces 4 values per loop p = concat([1],[for (i=[1:4:9]) [i+1,i+2,i+3,i+4]]); echo(p); ECHO: [1, [2, 3, 4, 5], [6, 7, 8, 9], [10, 11, 12, 13]] However, what I want is a flat list like: ECHO: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] I managed this weird contraption but that looses the "1" at the start echo([for (i=[0:1:len(p)-1], j=[0:1:len(p[i])-1]) p[i][j]]); ECHO: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] How do I do this? Sent from the OpenSCAD mailing list archive at Nabble.com._______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

Re: Add multiple items to a flat list in a loop.

 And of course I find a solution immediately after I posted. function flatten(a)=     [ for(x=a)       for(b=len(x)==undef? x:flatten(x)          )       b ]; But if there is any info that helps me to manage my lists better, I love to hear. Sent from the OpenSCAD mailing list archive at Nabble.com._______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org