Is this a bug? I have run across this sort of problem before, but in more
complex situations. This one is quite simple.
function lcm(a,b) =
assert(is_num(a) && is_num(b),"Invalid parameters to lcm")
abs(a*b) / gcd(a,b);
function gcd(a,b) =
b==0 ? abs(a) : gcd(b,a % b);
echo(lcm([60,12])); // Oops, called with list instead of two args
Result:
ERROR: Recursion detected calling function 'gcd' in file test105.scad, line
159
TRACE: called by 'gcd', in file test105.scad, line 159.
TRACE: called by 'gcd', in file test105.scad, line 159.
TRACE: called by 'gcd', in file test105.scad, line 159.
TRACE: called by 'gcd', in file test105.scad, line 159.
TRACE: called by 'gcd', in file test105.scad, line 159.
If I rewrite the code like this:
function lcm(a,b) =
let(
parmok = is_num(a) && is_num(b),
dummy=assert(parmok,"Invalid parameters to lcm")
)
abs(a*b) / gcd(a,b);
function gcd(a,b) =
b==0 ? abs(a) : gcd(b,a % b);
echo(lcm([60,12])); // Oops, called with list instead of two args
Then I get the expected behavior:
ERROR: Assertion 'parmok' failed: "Invalid parameters to lcm" in file
test105.scad, line 145
TRACE: called by 'lcm', in file test105.scad, line 152.
TRACE: called by 'echo', in file test105.scad, line 152.
--
Sent from: http://forum.openscad.org/
Probably, but it seems fixed in 2019.10.06.
Admin - email* me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.
--
Sent from: http://forum.openscad.org/