discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: [OpenSCAD] "Unpack" a vector

B
Bananapeel
Fri, Dec 5, 2014 6:27 PM

That's right, you need a new version. Get the "Development Snapshot" from the
downloads page.

Maybe there is a neater or faster way of doing sum, but this seems to do the
job:

/*
sum(vector) - Calculate the sum of all elements in a vector of numbers
*/
function sum(v, i=0) =
len(v) > i ? v[i] + sum(v, i+1) : 0;

If the list is empty (or the end of the list is reached), return 0. Else,
return the current element plus the sum of the rest of the list.

--
View this message in context: http://forum.openscad.org/Unpack-a-vector-tp10350p10377.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

That's right, you need a new version. Get the "Development Snapshot" from the downloads page. Maybe there is a neater or faster way of doing sum, but this seems to do the job: /* sum(vector) - Calculate the sum of all elements in a vector of numbers */ function sum(v, i=0) = len(v) > i ? v[i] + sum(v, i+1) : 0; If the list is empty (or the end of the list is reached), return 0. Else, return the current element plus the sum of the rest of the list. -- View this message in context: http://forum.openscad.org/Unpack-a-vector-tp10350p10377.html Sent from the OpenSCAD mailing list archive at Nabble.com.