discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Length of vector members

LB
L Boyd
Thu, Sep 24, 2015 2:29 PM

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.

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.
NH
nop head
Thu, Sep 24, 2015 2:36 PM

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 lboyd@frontiernet.net 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@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

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 <lboyd@frontiernet.net> 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@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
DM
doug moen
Thu, Sep 24, 2015 2:44 PM

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 lboyd@frontiernet.net 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@lists.openscad.org javascript:;
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

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 <lboyd@frontiernet.net> 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@lists.openscad.org <javascript:;> > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > >
LB
L Boyd
Thu, Sep 24, 2015 2:51 PM

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.

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.
LB
L Boyd
Thu, Sep 24, 2015 2:54 PM

I meant to say:
It is intentional for a valid reason.

--
View this message in context: http://forum.openscad.org/Length-of-vector-members-tp13971p13975.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I meant to say: It is intentional for a valid reason. -- View this message in context: http://forum.openscad.org/Length-of-vector-members-tp13971p13975.html Sent from the OpenSCAD mailing list archive at Nabble.com.
J
jon
Thu, Sep 24, 2015 2:56 PM

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
Discuss@lists.openscad.org
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

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 > Discuss@lists.openscad.org > 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 > >
LB
L Boyd
Thu, Sep 24, 2015 7:56 PM

I forgot about [1] and [] being valid vectors

--
View this message in context: http://forum.openscad.org/Length-of-vector-members-tp13971p13979.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I forgot about [1] and [] being valid vectors -- View this message in context: http://forum.openscad.org/Length-of-vector-members-tp13971p13979.html Sent from the OpenSCAD mailing list archive at Nabble.com.
LB
L Boyd
Thu, Sep 24, 2015 8:00 PM

I think examples of this in the manual would be useful. That was actually
what I was working on when I discovered this unexpected behaviour.

--
View this message in context: http://forum.openscad.org/Length-of-vector-members-tp13971p13980.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I think examples of this in the manual would be useful. That was actually what I was working on when I discovered this unexpected behaviour. -- View this message in context: http://forum.openscad.org/Length-of-vector-members-tp13971p13980.html Sent from the OpenSCAD mailing list archive at Nabble.com.