[OpenSCAD] Incrementing a variable doesn't work as expected.

nigeljohnson73 nigel at nigeljohnson.net
Wed Apr 1 04:51:53 EDT 2015


Doh!!! yep.

I moved the conditional calling, but this is still not playing nicely:

function cpos(s, n) = (n == -1) ? (0) : ( cpos(s,n-1) + (s[n]==".") ? 2 : 4
); 


echo ("--.-, 0: ", cpos("--.",0));
echo ("--.-, 1: ", cpos("--.",1));
echo ("--.-, 2: ", cpos("--.",2));
echo ("--.-, 3: ", cpos("--.",3));

ECHO: "--.-, 0: ", 4
ECHO: "--.-, 1: ", 4
ECHO: "--.-, 2: ", 4
ECHO: "--.-, 3: ", 4

I have also noticed a problem in that 0 should be 0 which I'll fix later,
but that aside, I would expect the following

ECHO: "--.-, 0: ", 4
ECHO: "--.-, 1: ", 8
ECHO: "--.-, 2: ", 10
ECHO: "--.-, 3: ", 14




--
View this message in context: http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12275.html
Sent from the OpenSCAD mailing list archive at Nabble.com.




More information about the Discuss mailing list