OskarLinde / scad-utils

Utility libraries for OpenSCAD
MIT License
245 stars 83 forks source link

WARNING: len() parameter could not be converted, in file scad-utils/trajectory.scad, line 7 #10

Open dpellegr opened 5 years ago

dpellegr commented 5 years ago

Hi, the latest OpenSCAD version produces the warning above, for example when running the list-comprehension-demos/toothed-belt.scad

I thought that to be be trivially fixable, but I have found the following behavior hard to grasp:

vec_is_undef([1,2,3,undef], index_=3) == true
vec_is_undef([1,2,3,undef,4], index_=3) == false

What is the rationale behind that? Do we actually need it?

thomaskilian commented 4 years ago

I have a similar issue (but in my own scad file). Using the old SCAD does not croak. Too bad since the "compiler warnings" are not really present in the old version compared to the new one.

dpellegr commented 4 years ago

@thomaskilian Please note that this is not the OpenSCAD repository, but the one of library scad-utils. If you have issues in your own scad file, than the right place to ask is the OpenSCAD forum showing your own code.

thomaskilian commented 4 years ago

Oops. I got here by Google and it just looked as being the right place. Anyhow, seems to be a general issue with the new OpenSCAD.

dpellegr commented 4 years ago

@thomaskilian Plenty of times it can easily be resolved. In this specific case of scad-utils it is not so obvious (at least to me) how to adjust the code.

thomaskilian commented 4 years ago

Well, it might give me the kick to go on with my "Python-SCAD-Pre-Compiler" where I can overcome the many limits of OpenSCAD. From a compiler construction view this language is sub-optimal. Well, it's free so no one to blame :-)

uqs commented 2 years ago

Did anyone find a workaround for this yet? This makes some projects out there unable to render :(

szero commented 2 years ago

its because len() function can be used on string variables only now, before it returned length of other types too, quickfix is to convert any variable into string before using len on it as such len(str(x)), here are lines in question that are wrong in trajectory module: Line 4 and Line 7

drf5n commented 2 years ago

Looking at the examples from https://en.wikibooks.org/w/index.php?title=OpenSCAD_User_Manual/Mathematical_Functions&stable=0#len the len(str(x)) workaround isn't good:

a=6; len_a=len(a);
echo(a,len_a);
x=6; len_x=len(str(x));
echo(x,len_x);
y=66; len_y=len(str(y));
echo(y,len_y);
WARNING: len() parameter could not be converted in file , line 1
ECHO: 6, undef
ECHO: 6, 1
ECHO: 66, 2