Length of vector members

8 messages
Open this post in threaded view
|

Length of vector members

 When using len() for the length of vector members, a single numeric value returns undef rather than 1. Examples:    a = [[1,2],3,"string"];    echoing the string part and lengths    ECHO: "a   = ", [[1, 2], 3, "string"], " length = ", 3  ECHO: "a[0] = ", [1, 2], " length = ", 2    so far so good, but    ECHO: "a[1]   = ", 3, " length = ", undef  ECHO: "a[0][1] = ", 2, " length = ", undef    no, it is not related to having a mixed vector    b=[5,4,3,1];  ECHO: "b   = ", [5, 4, 3, 1], " length = ", 4  ECHO: "b[0] = ", 5, " length = ", undef  for the string everything behaves great    ECHO: "a[2]   = ", "string", " length = ", 6  ECHO: "a[2][1]   = ", "t", " length = ", 1 Larry
Open this post in threaded view
|

Re: Length of vector members

 I think that is correct because a single number is not a vector and hence does not have a length. It is different from a vector of length 1. I also make use of it to test if an arg is a vector, or a scalar.On 24 September 2015 at 15:29, L Boyd wrote:When using len() for the length of vector members, a single numeric value returns undef rather than 1. Examples:  a = [[1,2],3,"string"];  echoing the string part and lengths  ECHO: "a   = ", [[1, 2], 3, "string"], " length = ", 3  ECHO: "a[0] = ", [1, 2], " length = ", 2  so far so good, but  ECHO: "a[1]   = ", 3, " length = ", undef  ECHO: "a[0][1] = ", 2, " length = ", undef  no, it is not related to having a mixed vector  b=[5,4,3,1];  ECHO: "b   = ", [5, 4, 3, 1], " length = ", 4  ECHO: "b[0] = ", 5, " length = ", undef  for the string everything behaves great  ECHO: "a[2]   = ", "string", " length = ", 6  ECHO: "a[2][1]   = ", "t", " length = ", 1 -- View this message in context: http://forum.openscad.org/Length-of-vector-members-tp13971.html 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 _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

Re: Length of vector members

 In reply to this post by L Boyd The len() function is only defined for vectors and strings. It returns undef for any other type of argument. Lots of code relies on this behaviour so don't expect it to change.On Thursday, 24 September 2015, L Boyd <[hidden email]> wrote:When using len() for the length of vector members, a single numeric value returns undef rather than 1. Examples:  a = [[1,2],3,"string"];  echoing the string part and lengths  ECHO: "a   = ", [[1, 2], 3, "string"], " length = ", 3  ECHO: "a[0] = ", [1, 2], " length = ", 2  so far so good, but  ECHO: "a[1]   = ", 3, " length = ", undef  ECHO: "a[0][1] = ", 2, " length = ", undef  no, it is not related to having a mixed vector  b=[5,4,3,1];  ECHO: "b   = ", [5, 4, 3, 1], " length = ", 4  ECHO: "b[0] = ", 5, " length = ", undef  for the string everything behaves great  ECHO: "a[2]   = ", "string", " length = ", 6  ECHO: "a[2][1]   = ", "t", " length = ", 1 -- View this message in context: http://forum.openscad.org/Length-of-vector-members-tp13971.html Sent from the OpenSCAD mailing list archive at Nabble.com. _______________________________________________ OpenSCAD mailing list Discuss@... 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
|

Re: Length of vector members

 In reply to this post by nophead Ok, so it is intentional for a reason, not a bug. Larry
Open this post in threaded view
|

Re: Length of vector members

 I meant to say: It is intentional for a valid reason. Larry
Open this post in threaded view
|

Re: Length of vector members

 In reply to this post by L Boyd Would it make sense to include examples such as this in the documentation in order to prevent similar questions in the future? On 9/24/2015 10:51 AM, L Boyd wrote: > Ok, so it is intentional for a reason, not a bug. > > > > -- > View this message in context: http://forum.openscad.org/Length-of-vector-members-tp13971p13974.html> 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> > > > ----- > No virus found in this message. > Checked by AVG - www.avg.com > Version: 2015.0.6140 / Virus Database: 4431/10692 - Release Date: 09/24/15 > > _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org