Loading

Quirks of argument input format

Please Login to Comment

Hay guys, I only just noticed these quirks to do with inputting arguments, and was curious to know what other people made of them, would you consider them bugs?

Within the parenthesis of a function, If you put a labeled variable in front of an unlabeled variable, (even if it is in sequence) this seems to foul up the operation.
The label might be redundant, but I don't see any need for it to break the code. see (Example 1)

I've only looked at the one shape but I notice with the cylinder that without labels the second vale is assumed to be "r1" rather than "r", which means there is no specified value for "r2" so it is given a default value of 1. see (Example 2)
I think this one probably does constitute a small error.

// Example 1
function add(a,b,c)= a+b+c;
echo("test 1 = ",add(a=4, b=4, c=4)); // = 12
echo("test 2 = ",add( 4, 4, 4)); // = 12
echo("test 3 = ",add(a=4, 4, 4)); // = undef
echo("test 4 = ",add( 4, b=4, 4)); // = undef
echo("test 5 = ",add( 4, b=4, c=4)); // = 12
echo("test 6 = ",add( 4, 4, c=4)); // = 12

// Example 2
cylinder(h=10, r=2); // fine
translate([6 ,0,0]) cylinder( 10, 2); // wtf?
translate([12,0,0]) cylinder( 10, r=2); // fine

The description in the OpenSCAD User Manual on how to call the cylinder function gives a clue:

Parameter names are optional if given in the order shown here. If a parameter is named, all following parameters must also be named.

Since it is documented behaviour, I wouldn't consider this being a bug.

I must admit It didn't occur to me to look on the User Manual, I don't ever remember noticing a descution on how to call for other shaps etc.

As you say, it probably cant be considers a bug, but the more i think about it, the more it strikes me as poorly coded. I would have made "r" and "r1" interchangable and given "r2" a defult value = r or r1.

Interesting. I know openscad sometimes has quite large differences from "traditional" languages.
I tried the following with example 1:

function add(a=0,b=0,c=0)= a+b+c;
echo("test 1 = ",add(a=4, b=4, c=4)); // = 12
echo("test 2 = ",add( 4, 4, 4)); // = 12
echo("test 3 = ",add(a=4, 4, 4)); // = 8
echo("test 4 = ",add( 4, b=4, 4)); // = 8
echo("test 5 = ",add( 4, b=4, c=4)); // = 12
echo("test 6 = ",add( 4, 4, c=4)); // = 12

which gave strange results. Maybe a direction for interpretation of the behaviour?

If nothing else, it makes a good case for not assigning default values to the variables, inside the function declaration.
Not receaving the error messages when thers a problem is defanly not desirable.

I did a larger set of tests but still cant see a consistent patten. It's test 2 that is the anomaly, it should = 40.

function add(a=0,b=0,c=0,d=0)= a+b+c+d;
echo("test 1 = ",add(a=4, b=8, c=20, d=40)); // = 72 abcd
echo("test 2 = ",add(a=4, b=8, c=20, 40)); // = 68 -bcd
echo("test 3 = ",add(a=4, b=8, 20, 40)); // = 60 --cd
echo("test 4 = ",add(a=4, 8, 20, 40)); // = 68 -bcd
echo("test 5 = ",add( 4, 8, 20, 40)); // = 72 abcd
echo("test 6 = ",add( 4, b=8, c=20, d=40)); // = 72 abcd
echo("test 7 = ",add( 4, 8, c=20, d=40)); // = 72 abcd
echo("test 8 = ",add( 4, 8, 20, d=40)); // = 72 abcd
echo("test 9 = ",add(a=4, 8, 20, 40)); // = 68 -bcd
echo("test 10 = ",add( 4, b=8, 20, 40)); // = 64 a-cd
echo("test 11 = ",add( 4, 8, c=20, 40)); // = 52 ab-d
echo("test 12 = ",add( 4, 8, 20, d=40)); // = 72 abcd

Hello, all I can say at a quick glance, is that it seems to verify the sentence:

"If a parameter is named, all following parameters must also be named".

Now, I do not understand the underlying logic.

Sorry, my error (erased my comment)