MichaelAtOz wrote
This is how I lay them out for clarity, with tabs aligning the test, '?'
&':'
function x(p) =
(test)
? true_expression
: false_expression;
function many(p) =
(test1)
? (test1-t)
? t_expr
: f_expr
: (test1-f)
? t_expr
: f_expr; // etc
Yea, that's a more complete version of what I presented. In summary, for a
construct like: "f = (A)?B:C", next-level branch can be applied to either B
or C or both. My example only shows it applied to C so can be presented
like:
f= (A) ?
B
: (C) ?
C1
: C2
When both branches are nested, your form is a better way:
f= (A)
? (B)
? B1
: B2
: (C)
? C1
: C2
View this message in context: http://forum.openscad.org/function-with-if-case-statement-tp18882p18926.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
The parenthesis are unnecessary because ? : has the lowest operator
precedence.
On 4 November 2016 at 01:18, runsun runsun@gmail.com wrote:
MichaelAtOz wrote
This is how I lay them out for clarity, with tabs aligning the test, '?'
&':'
function x(p) =
(test)
? true_expression
: false_expression;
function many(p) =
(test1)
? (test1-t)
? t_expr
: f_expr
: (test1-f)
? t_expr
: f_expr; // etc
Yea, that's a more complete version of what I presented. In summary, for a
construct like: "f = (A)?B:C", next-level branch can be applied to either B
or C or both. My example only shows it applied to C so can be presented
like:
f= (A) ?
B
: (C) ?
C1
: C2
When both branches are nested, your form is a better way:
f= (A)
? (B)
? B1
: B2
: (C)
? C1
: C2
View this message in context: http://forum.openscad.org/
function-with-if-case-statement-tp18882p18926.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
Comments are also unnecessary, but I find enclosing the expression is a belt
& braces.
Started when this didn't work.
tn=1;
tb=true;
if tn echo("true tn");
if tb echo("true tb");
Yes the wiki says 'if (expr)' but I can't see why 'if boolean_var' is not
logical.
So, reflex, wrap expressions in '(' & ')'
Admin - PM 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.
View this message in context: http://forum.openscad.org/function-with-if-case-statement-tp18882p18933.html
Sent from the OpenSCAD mailing list archive at Nabble.com.