# A = A + 1;

44 messages
123
Open this post in threaded view
|

## Re: A = A + 1;

 On Wed, 4 Feb 2015 05:58:24 -0700 (MST) Bananapeel <[hidden email]> wrote: > adriang wrote > > Does the following > > echo(vsum([[1,2],[3,4]])); > > work for your definition? > > I don't know any normal language that would automatically allow > vsum([1,2,3,8]) and vsum([[1,2],[3,4]]) into the same function and give a > sensible result. M, Haskell, Java, C++ templates,  Smalltalk.... > That's like applying an integer function to a string and expecting it to magically figure out what you want. Which is what many languages do. > Would you expect the result to be 10 or [4, 6]? What matters is that the function is defined sensibly and behaviour defined for that type and to be useful. Eg is the average of  matrix of 3D co-ordinates more usefully a set of vectors or a single point giving the "middle" (for that definition) of the object ? Alan _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: A = A + 1;

 Here is a version that works with vectors and vectors of vectors:function sum(v, i = 1) = i < len(v) ? v[i] + sum(v, i+1) : len(v) ? v[0] : 0; echo(sum([])); echo(sum([1,2,3,8])); echo(sum([[1,2],[3,4]]));ECHO: 0 ECHO: 14 ECHO: [4, 6]On 4 February 2015 at 14:28, Alan Cox wrote:On Wed, 4 Feb 2015 05:58:24 -0700 (MST) Bananapeel <[hidden email]> wrote: > adriang wrote > > Does the following > > echo(vsum([[1,2],[3,4]])); > > work for your definition? > > I don't know any normal language that would automatically allow > vsum([1,2,3,8]) and vsum([[1,2],[3,4]]) into the same function and give a > sensible result. M, Haskell, Java, C++ templates,  Smalltalk.... > That's like applying an integer function to a string and expecting it to magically figure out what you want. Which is what many languages do. > Would you expect the result to be 10 or [4, 6]? What matters is that the function is defined sensibly and behaviour defined for that type and to be useful. Eg is the average of  matrix of 3D co-ordinates more usefully a set of vectors or a single point giving the "middle" (for that definition) of the object ? Alan _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|